# \[Archive\] Keeping web3auth connection alive after Page Refresh

**URL:** <https://builder.metamask.io/t/archive-keeping-web3auth-connection-alive-after-page-refresh/1831>\
**Category:** Embedded Wallets (Web3Auth)\
**Created:** [July 21, 2023, 5:16am UTC](https://builder.metamask.io/t/archive-keeping-web3auth-connection-alive-after-page-refresh/1831 "2023-07-21T05:16:06Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![bjkim](https://avatars.discourse-cdn.com/v4/letter/b/57b2e6/32.png) [@bjkim](https://builder.metamask.io/u/bjkim)\
**Post date:** [July 21, 2023, 5:16am UTC](https://builder.metamask.io/t/archive-keeping-web3auth-connection-alive-after-page-refresh/1831/1 "2023-07-21T05:16:06Z")

</div>

> **🏛 Archived Content from Web3Auth Community**
> 
> This topic was originally posted by **bjkim** on 7/21/2023.  
> This content has been migrated from our previous community forum to preserve valuable discussions.

* * *

I did a login test on the [demo site](https://main.dz7pna503r6cc.amplifyapp.com/) specified in [Web3Auth-SFA-Read](https://github.com/Web3Auth/single-factor-auth-web)

When I try to refresh, the login session doesn’t seem to persist. (In Plug and Play, the login session was maintained when refreshing)

Do I need to add any other code of my own to keep it refreshed?

**Please provide the following details too when asking for help in this category:**

- SDK Version: SFA v6.4.1
- Verifier Details:
  - Verifier Name:
  - JWKS Endpoint:
  - Sample idToken(JWT)

---

<div class="post-metadata">

**Author:** ![yashovardhan](https://yyz1.discourse-cdn.com/flex011/user_avatar/builder.metamask.io/yashovardhan/32/1526_2.png) [@yashovardhan](https://builder.metamask.io/u/yashovardhan)\
**Post date:** [July 21, 2023, 7:56am UTC](https://builder.metamask.io/t/archive-keeping-web3auth-connection-alive-after-page-refresh/1831/2 "2023-07-21T07:56:35Z")

</div>

Hey @bjkim

Session Management does exist in all our SFA SDKs. It works very similarly to how PnP SDKs handle session management. You can install the latest version of the SDK to experience it.

Thanks for pointing out the demo. It was not updated with the latest SDK, we’re in the process of doing that. We’ll make sure it is up to date as soon as possible.

---

<div class="post-metadata">

**Author:** ![bjkim](https://avatars.discourse-cdn.com/v4/letter/b/57b2e6/32.png) [@bjkim](https://builder.metamask.io/u/bjkim)\
**Post date:** [July 25, 2023, 1:23am UTC](https://builder.metamask.io/t/archive-keeping-web3auth-connection-alive-after-page-refresh/1831/3 "2023-07-25T01:23:58Z")

</div>

[SFA Demo code Link](https://github.com/Web3Auth/web3auth-core-kit-examples/tree/main/single-factor-auth-web/sfa-react-example)

I updated the library to the latest in the demo code and tested it.

It still doesn’t seem to keep the session after refreshing.

- get ethProvider → refresh → ethProvider is null

### ISSUE VIDEO LINK

```
  <a href="https://drive.google.com/file/d/1nUEmEgvQxORCo73fNRHy02iaq1apRXPD/view?usp=sharing" target="_blank" rel="noopener">drive.google.com</a>

```

### [화면 기록 2023-07-25 오전 10.19.51.mov](https://drive.google.com/file/d/1nUEmEgvQxORCo73fNRHy02iaq1apRXPD/view?usp=sharing)

Google Drive file.

Do I need to add any other settings???

```auto
// package.json
"@web3auth/base": "^6.1.4",
"@web3auth/ethereum-provider": "^6.1.5",
"@web3auth/single-factor-auth": "^6.4.1",

```

---

<div class="post-metadata">

**Author:** ![yashovardhan](https://yyz1.discourse-cdn.com/flex011/user_avatar/builder.metamask.io/yashovardhan/32/1526_2.png) [@yashovardhan](https://builder.metamask.io/u/yashovardhan)\
**Post date:** [July 25, 2023, 3:33am UTC](https://builder.metamask.io/t/archive-keeping-web3auth-connection-alive-after-page-refresh/1831/4 "2023-07-25T03:33:48Z")

</div>

This example code has to be rewritten properly. We’ll make sure to do that. Basically calling the init function in useEffect (constructor) will the key here.  
Session Management kicks in once init function is called.

---

<div class="post-metadata">

**Author:** ![bjkim](https://avatars.discourse-cdn.com/v4/letter/b/57b2e6/32.png) [@bjkim](https://builder.metamask.io/u/bjkim)\
**Post date:** [July 25, 2023, 5:35am UTC](https://builder.metamask.io/t/archive-keeping-web3auth-connection-alive-after-page-refresh/1831/5 "2023-07-25T05:35:08Z")

</div>

Will the existing demo code and configuration change a lot?

After switching from PNP to SFA in my project, the session is not maintained.

```auto
useEffect(() => {
   async function init() {
      try {
          setIsLoading(true);
          const web3authSfa = new Web3Auth({
             clientId,
             web3AuthNetwork: 'testnet',
             usePnPKey: true,
          });
      const privateKeyProvider = new EthereumPrivateKeyProvider({
         config: { chainConfig: CHAIN_CONFIG[CHAIN_ENV] },
      });
      await web3authSfa.init(privateKeyProvider);
      setWeb3authSFAuth(web3authSfa);
   } catch (error) {
      console.error(error);
   } finally {
      setIsLoading(false);
   }

```

I made the code similar to PNP No modal, but does the code change a lot here?

And… Is there some other example code I can refer to somewhere?

---

<div class="post-metadata">

**Author:** ![jh\_kim](https://avatars.discourse-cdn.com/v4/letter/j/ac91a4/32.png) [@jh\_kim](https://builder.metamask.io/u/jh_kim)\
**Post date:** [July 25, 2023, 8:51am UTC](https://builder.metamask.io/t/archive-keeping-web3auth-connection-alive-after-page-refresh/1831/6 "2023-07-25T08:51:08Z")

</div>

Any update? It is still not working.

---

<div class="post-metadata">

**Author:** ![bjkim](https://avatars.discourse-cdn.com/v4/letter/b/57b2e6/32.png) [@bjkim](https://builder.metamask.io/u/bjkim)\
**Post date:** [July 27, 2023, 9:04am UTC](https://builder.metamask.io/t/archive-keeping-web3auth-connection-alive-after-page-refresh/1831/7 "2023-07-27T09:04:40Z")

</div>

Can I save the provider here to maintain the session? It seems to work fine when I refresh.

```auto
useEffect(() => {
   async function init() {
      try {
          setIsLoading(true);
          const web3authSfa = new Web3Auth({
             clientId,
             web3AuthNetwork: 'testnet',
             usePnPKey: true,
          });
      const privateKeyProvider = new EthereumPrivateKeyProvider({
         config: { chainConfig: CHAIN_CONFIG[CHAIN_ENV] },
      });
      await web3authSfa.init(privateKeyProvider);
      setWeb3authSFAuth(web3authSfa);
      // &lt;-- added
      if (web3AuthInstance.sessionId &amp;&amp; web3AuthInstance.provider) {
         setProvider(web3AuthInstance.provider);
       }
     // --&gt;
   } catch (error) {
      console.error(error);
   } finally {
      setIsLoading(false);
   }

```

---

<div class="post-metadata">

**Author:** ![archit](https://avatars.discourse-cdn.com/v4/letter/a/57b2e6/32.png) [@archit](https://builder.metamask.io/u/archit)\
**Post date:** [July 28, 2023, 5:24pm UTC](https://builder.metamask.io/t/archive-keeping-web3auth-connection-alive-after-page-refresh/1831/8 "2023-07-28T17:24:35Z")

</div>

yes, you can save the provider after init if a session is there.  
Also, we are working on updating the SFA examples to reflect session management
