While using the Web3Auth PnP NoModal SDK with UX_MODE.REDIRECT, I noticed that the code following the web3auth.connectTo() call does not seem to execute. This creates a challenge because the login() function appears to be the only logical place to record the timestamp of the user’s last login in our backend database.
For instance, in this snippet from the Web3Auth Quickstart, it seems the code after the connectTo() call doesn’t run—potentially due to the redirect initiated by connectTo. Reference: Web3Auth Quickstart.
const login = async () => {
const web3authProvider = await web3auth.connectTo(WALLET_ADAPTERS.AUTH, {
loginProvider: "google",
});
// Code after this point does **not** execute
setProvider(web3authProvider);
if (web3auth.connected) {
setLoggedIn(true);
}
};
Could you confirm whether this behavior is expected? If so, do you have any suggestions for a workaround? Using the addListener on the CONNECTED event doesn’t seem viable in this case, as it would also trigger on a page refresh when the user was previously connected, which isn’t ideal for logging purposes.
For the record, this is not the same behavior when setting UX_MODE.POPUP. In this configuration, the code after connectTo() is executed accordingly.
Thank you for reaching out and sharing the details of your issue with the Web3Auth PnP NoModal SDK. I see you’re facing a challenge with the code not executing after the web3auth.connectTo() call.
Here’s a summary of the information we have:
SDK Details: Plug n Play (PnP) NoModal
Issue: Code after web3auth.connectTo() not executing
Regarding your question, it seems like the behavior you’re observing might be expected due to the way the connectTo() method handles login, including potential redirects.
As a workaround, one option could be to listen for the CONNECTED event in a way that filters out triggers caused by page refreshes. Another potential solution is to use the afterLogin callback, if available in your version of the SDK, which may allow you to run code after successfully connecting without relying solely on the flow directly after the connectTo() call.
To help the support team address your issue more efficiently, could you please provide the following details?
SDK Version Number
Platform (e.g., Next.js, React)
Additionally, if you have any console screenshots or relevant code snippets around the web3auth.connectTo() call, that would be helpful as well.
Thanks again for your query, and we’re here to assist you!
Note: This response was generated by an AI bot and may require further verification. The Web3Auth support team has tracked this issue and will be responding as soon as possible.
Hey I tried to run locally the NEXT JS Quick Start, and change the UX mode to redirect. It works fine for me, can you see if there are any errors in the console. If possible, can you share the recording?
There are no errors, and the page redirects in the browser when connectTo is executed. You mentioned that the code following connectTo with the “auth” verifier does work for you—how are you verifying this? I’m invoking a NextJS server action immediately after connectTo, but it doesn’t execute on the server. However, calling the same server action before connectTo executes as expected.
I think the flow is correct, when you use the redirect flow, it basically redirects you to a new page, and hence the code after connectTo is not executed. If you want to execute something when the Web3Auth is connected, you can listen to Adapter events.
@ayush My concern is that I need to capture the exact moment a user actually logs in. With your approach, this triggers every time the user refreshes the page, not just when they click the “login” button and successfully log in to the application.
If we agree that no code runs after connectTo when using the REDIRECT flow, we can consider this ticket resolved.