# \[Archive\] Persisting web3auth provider through refrsh

**URL:** <https://builder.metamask.io/t/archive-persisting-web3auth-provider-through-refrsh/1714>\
**Category:** Embedded Wallets (Web3Auth)\
**Created:** [July 25, 2023, 5:43am UTC](https://builder.metamask.io/t/archive-persisting-web3auth-provider-through-refrsh/1714 "2023-07-25T05:43:43Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![tarun](https://avatars.discourse-cdn.com/v4/letter/t/ce7236/32.png) [@tarun](https://builder.metamask.io/u/tarun)\
**Post date:** [July 25, 2023, 5:43am UTC](https://builder.metamask.io/t/archive-persisting-web3auth-provider-through-refrsh/1714/1 "2023-07-25T05:43:43Z")

</div>

> **🏛 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);

```

}  
return { web3auth, web3Instance, userInfo };  
};

export { getWeb3AuthInstance };

---

<div class="post-metadata">

**Author:** ![vjgee](https://avatars.discourse-cdn.com/v4/letter/v/b5e925/32.png) [@vjgee](https://builder.metamask.io/u/vjgee)\
**Post date:** [July 25, 2023, 7:57am UTC](https://builder.metamask.io/t/archive-persisting-web3auth-provider-through-refrsh/1714/2 "2023-07-25T07:57:41Z")

</div>

@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

---

<div class="post-metadata">

**Author:** ![maharshi](https://yyz1.discourse-cdn.com/flex011/user_avatar/builder.metamask.io/maharshi/32/1525_2.png) [@maharshi](https://builder.metamask.io/u/maharshi)\
**Post date:** [July 25, 2023, 8:51am UTC](https://builder.metamask.io/t/archive-persisting-web3auth-provider-through-refrsh/1714/3 "2023-07-25T08:51:58Z")

</div>

@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](https://github.com/Web3Auth/web3auth-pnp-examples/blob/main/web-modal-sdk/blockchain-connection-examples/evm-modal-example) for your convenience. Let me know if this helps you.

---

<div class="post-metadata">

**Author:** ![puneet](https://avatars.discourse-cdn.com/v4/letter/p/b9e5f3/32.png) [@puneet](https://builder.metamask.io/u/puneet)\
**Post date:** [August 1, 2023, 1:22pm UTC](https://builder.metamask.io/t/archive-persisting-web3auth-provider-through-refrsh/1714/4 "2023-08-01T13:22:58Z")

</div>

@maharshi  
Even I am facing the same issue  
In the offcial example repo [code](https://github.com/Web3Auth/web3auth-pnp-examples/blob/main/web-modal-sdk/evm/react-evm-modal-example/src/App.tsx)

```auto
  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.

---

<div class="post-metadata">

**Author:** ![maharshi](https://yyz1.discourse-cdn.com/flex011/user_avatar/builder.metamask.io/maharshi/32/1525_2.png) [@maharshi](https://builder.metamask.io/u/maharshi)\
**Post date:** [August 1, 2023, 4:25pm UTC](https://builder.metamask.io/t/archive-persisting-web3auth-provider-through-refrsh/1714/5 "2023-08-01T16:25:06Z")

</div>

hey @puneet please me know the version of the SDK you are using

---

<div class="post-metadata">

**Author:** ![puneet](https://avatars.discourse-cdn.com/v4/letter/p/b9e5f3/32.png) [@puneet](https://builder.metamask.io/u/puneet)\
**Post date:** [August 3, 2023, 6:25am UTC](https://builder.metamask.io/t/archive-persisting-web3auth-provider-through-refrsh/1714/6 "2023-08-03T06:25:19Z")

</div>

@maharshi  
I am also using SDK Version: 6.1.3

---

<div class="post-metadata">

**Author:** ![maharshi](https://yyz1.discourse-cdn.com/flex011/user_avatar/builder.metamask.io/maharshi/32/1525_2.png) [@maharshi](https://builder.metamask.io/u/maharshi)\
**Post date:** [August 22, 2023, 10:52pm UTC](https://builder.metamask.io/t/archive-persisting-web3auth-provider-through-refrsh/1714/7 "2023-08-22T22:52:34Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![maharshi](https://yyz1.discourse-cdn.com/flex011/user_avatar/builder.metamask.io/maharshi/32/1525_2.png) [@maharshi](https://builder.metamask.io/u/maharshi)\
**Post date:** [October 31, 2023, 6:44am UTC](https://builder.metamask.io/t/archive-persisting-web3auth-provider-through-refrsh/1714/8 "2023-10-31T06:44:59Z")

</div>

Do you still face this issue? I would be glad to assist you more on this if required.
