# Cannot clear state and reuse web3auth instance for single-factor-auth and Node mode

**URL:** <https://builder.metamask.io/t/cannot-clear-state-and-reuse-web3auth-instance-for-single-factor-auth-and-node-mode/1089>\
**Category:** Embedded Wallets (Web3Auth)\
**Created:** [January 17, 2025, 7:40am UTC](https://builder.metamask.io/t/cannot-clear-state-and-reuse-web3auth-instance-for-single-factor-auth-and-node-mode/1089 "2025-01-17T07:40:10Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![jcani](https://yyz1.discourse-cdn.com/flex011/user_avatar/builder.metamask.io/jcani/32/90_2.png) [@jcani](https://builder.metamask.io/u/jcani)\
**Post date:** [January 17, 2025, 7:40am UTC](https://builder.metamask.io/t/cannot-clear-state-and-reuse-web3auth-instance-for-single-factor-auth-and-node-mode/1089/1 "2025-01-17T07:40:10Z")

</div>

> **🏛 Content from Web3Auth Community**
> 
> This topic was originally posted by **jcani** on 1/17/2025.  
> This content has been migrated from our previous community forum to preserve valuable discussions.

* * *

When using the single-factor-auth SDK in Node mode, it seems that there is no way to disconnect in order to clear the internal state/status of the instantiated instance after a connect.

Reading [the code in github for Web3Auth class](https://github.com/Web3Auth/single-factor-auth/blob/master/src/Web3Auth.ts) , the connect method [sets the status internal variable to be ADATPER\_STATUS.CONNECTED in \_finalizeLogin](https://github.com/Web3Auth/single-factor-auth/blob/master/src/Web3Auth.ts#L403).

However, the `logout` method, relies on t[he internal property `connected`, which depends on if session is active](https://github.com/Web3Auth/single-factor-auth/blob/master/src/Web3Auth.ts#L104). However, [when it’s NODE mode, the `sessionManager` is not instantiated.](https://github.com/Web3Auth/single-factor-auth/blob/master/src/Web3Auth.ts#L392).

This caused the `logout` method to always fail because the sdk instance was never “connected”.

In Node (backend) usecase, I should be able to init the sdk once and keep reusing it for different users. Unless there use-case is I am expected to recreate the SDK instance and reinitiate it everytime I need to use it? If so, why?

---

<div class="post-metadata">

**Author:** ![w3abot](https://avatars.discourse-cdn.com/v4/letter/w/4da419/32.png) [@w3abot](https://builder.metamask.io/u/w3abot)\
**Post date:** [January 17, 2025, 7:40am UTC](https://builder.metamask.io/t/cannot-clear-state-and-reuse-web3auth-instance-for-single-factor-auth-and-node-mode/1089/2 "2025-01-17T07:40:47Z")

</div>

Hi Jacky! Thanks for reaching out with such a detailed explanation. Let’s see if we can provide some guidance on this.

From what you’ve described, it appears you’re encountering an issue with the Web3Auth Single-Factor-Auth SDK when using it in Node mode. The main concern seems to be the inability to clear the internal state of the Web3Auth instance effectively for reuse across different users.

### From Your Details:

- **SDK** : Single-Factor-Auth (Plug n Play)
- **Mode** : Node Mode
- **Issue** : Inability to disconnect or clear state properly due to the `sessionManager` not being instantiated in Node mode.
- **Concern** : The `logout` method relies on `connected`, which isn’t instantiated in Node mode.

### Suggested Approach:

Given the issue you’re facing, it might indeed be expected to reinitialize the SDK instance when using it for different users in a backend setup. The lack of a `sessionManager` instantiation for Node mode implies that session management might need to occur at a higher application logic level, such as handling instantiation and cleanup per user session manually.

### What You Can Do:

- **Reinitialize Per Session** : As you suggested, creating a fresh instance of the SDK for each user session might be the required approach due to the lack of a session mechanism in Node mode.
- **Feature Request** : If this behavior doesn’t align with your needs, consider reaching out with a feature request. It might be helpful for others as well who require persistent sessions in Node mode.

You might also want to add your voice to the discussion on feature requests or improvements directly on their GitHub repository to potentially influence future SDK enhancements.

If you’d like further assistance or confirmation, feel free to ask! We’re here to help. 😊

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

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/metamaskbuilderhub/original/1X/082cfc3a14103b01cfa5ef7d85f1121a23fa3e81.png) [@system](https://builder.metamask.io/u/system)\
**Post date:** [January 31, 2025, 7:40am UTC](https://builder.metamask.io/t/cannot-clear-state-and-reuse-web3auth-instance-for-single-factor-auth-and-node-mode/1089/3 "2025-01-31T07:40:59Z")

</div>

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.

---

<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:** [February 6, 2025, 11:35pm UTC](https://builder.metamask.io/t/cannot-clear-state-and-reuse-web3auth-instance-for-single-factor-auth-and-node-mode/1089/4 "2025-02-06T23:35:16Z")

</div>



---

<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:** [February 6, 2025, 11:37pm UTC](https://builder.metamask.io/t/cannot-clear-state-and-reuse-web3auth-instance-for-single-factor-auth-and-node-mode/1089/5 "2025-02-06T23:37:27Z")

</div>

Hey @jcani ,

Thanks for bringing this up! I looked into it, and it does seem like `logout()` in **Node mode** isn’t working as expected since `SessionManager` isn’t instantiated, meaning the SDK never technically considers itself “connected.”

I’ve reached out to a senior engineer to confirm if the expected approach in backend use cases is to **recreate the SDK instance per request** or if there’s another way to properly clear state. Will update here once I get a response.

---

<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:** [February 10, 2025, 12:51pm UTC](https://builder.metamask.io/t/cannot-clear-state-and-reuse-web3auth-instance-for-single-factor-auth-and-node-mode/1089/6 "2025-02-10T12:51:39Z")

</div>

Hey @jcani  
This has been fixed in the latest minor release, please update the SFA SDK to the latest version and let me know if it works as you were expecting. And thanks for reporting this, folks like you help us make our offerings better.  
Here’s the relevant changelog: [fixes logout in node sdk · Web3Auth/single-factor-auth@cf3e13f · GitHub](https://github.com/Web3Auth/single-factor-auth/commit/cf3e13f5d80999a9fd03edf72fb1e7909d5f724d)

---

<div class="post-metadata">

**Author:** ![jcani](https://yyz1.discourse-cdn.com/flex011/user_avatar/builder.metamask.io/jcani/32/90_2.png) [@jcani](https://builder.metamask.io/u/jcani)\
**Post date:** [February 11, 2025, 2:43am UTC](https://builder.metamask.io/t/cannot-clear-state-and-reuse-web3auth-instance-for-single-factor-auth-and-node-mode/1089/7 "2025-02-11T02:43:37Z")

</div>

Lovely! Thanks for looking into this issue and fixing it so quickly @maharshi !

May I confirm that `9.4.0` is the right version to be used?

 ![](https://canada1.discourse-cdn.com/flex011/uploads/metamaskbuilderhub/original/1X/eee5f6470ae1c9616f9345db70fb6b9e698e7e0b.png)

```
  <a href="https://www.npmjs.com/package/@web3auth/single-factor-auth/v/9.4.0" target="_blank" rel="noopener nofollow ugc">npm</a>

```

 ![](https://canada1.discourse-cdn.com/flex011/uploads/metamaskbuilderhub/original/1X/22a7585780748ce9da398911759423d0ad861e12.png)

### [@web3auth/single-factor-auth](https://www.npmjs.com/package/@web3auth/single-factor-auth/v/9.4.0)

Multi chain wallet aggregator silent MFA for web3Auth. Latest version: 9.4.0, last published: 14 hours ago. Start using @web3auth/single-factor-auth in your project by running `npm i @web3auth/single-factor-auth`. There are 15 other projects in the...

---

<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:** [February 11, 2025, 3:30am UTC](https://builder.metamask.io/t/cannot-clear-state-and-reuse-web3auth-instance-for-single-factor-auth-and-node-mode/1089/8 "2025-02-11T03:30:57Z")

</div>

Yes, that’s correct @jcani
