Archived Content from Web3Auth Community
This topic was originally posted by tarun on 7/25/2023.
This content has been migrated from our previous community forum to preserve valuable discussions.
- 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 };