tarun
July 25, 2023, 5:43am
1
SDK Version: 6.1.3
Platform: Chrome Browser
After refreshing the page, I’m losing the Web3Auth provider. How can I retain the Web3Auth provider without requiring the user to log in again?
this is the custom function i am using :
import Web3 from “web3”;
import { allowedSocialMethods, numberToHex } from “…/Components/Auth/helpers”;
import { CHAIN_ID, WEB_3_AUTH_CLIENT_ID } from “…/config”;
import { Web3Auth } from “@web3auth /modal”;
import { WALLET_ADAPTERS } from “@web3auth /base”;
let web3Instance;
let web3auth;
let userInfo;
const getWeb3AuthInstance = async () => {
if (!web3Instance) {
web3auth = new Web3Auth({
clientId: WEB_3_AUTH_CLIENT_ID,
chainConfig: {
chainId: numberToHex(CHAIN_ID),
chainNamespace: “eip155”,
},
uiConfig: {
dark: true,
},
});
await web3auth.initModal({
modalConfig: {
[WALLET_ADAPTERS.OPENLOGIN]: allowedSocialMethods,
},
});
await web3auth.connect();
web3Instance = new Web3(web3auth.provider);
userInfo = await web3auth.getUserInfo();
}
return { web3auth, web3Instance, userInfo };
};
export { getWeb3AuthInstance };
2 Likes
vjgee
July 25, 2023, 7:57am
2
@tarun Thanks for your question.
Your request has been forwarded to a team and we will get back with further updates once more information becomes available
@tarun This might be happening because your code is not looking for already logged in sessions. Have a look at our examples. I’ll attach a link here for your convenience. Let me know if this helps you.
puneet
August 1, 2023, 1:22pm
4
@maharshi
Even I am facing the same issue
In the offcial example repo code
const login = async () => {
if (!web3auth) {
uiConsole("web3auth not initialized yet");
return;
}
const web3authProvider = await web3auth.connect();
setProvider(web3authProvider);
setLoggedIn(true);
};
I am losing the web3auth instance on refresh and then it is again showing modal asking for login.
hey @puneet please me know the version of the SDK you are using
puneet
August 3, 2023, 6:25am
6
@maharshi
I am also using SDK Version: 6.1.3
1 Like
Hey @puneet , do you have the useEffect in place in your code? I am asking this because the official example repo code works fine on my local.