Skip to content

feat: external wallet session management#2432

Open
hieu-w wants to merge 18 commits intomasterfrom
feat/External-wallet-session-management
Open

feat: external wallet session management#2432
hieu-w wants to merge 18 commits intomasterfrom
feat/External-wallet-session-management

Conversation

@hieu-w
Copy link
Copy Markdown
Member

@hieu-w hieu-w commented Apr 1, 2026

Jira Link

Description

Fix verifySignedChallenge call in the WalletConnect v2 connector to match the updated VerifySignedChallengeParams interface from @toruslabs/base-controllers.

The baseEvmConnector and baseSolanaConnector were already updated but walletConnectV2Connector was missed:

  • Added missing deviceInfo: getDeviceInfo() parameter (required by VerifySignedChallengeParams)
  • Updated return type handling: verifySignedChallenge now returns SiwwTokens (with idToken, accessToken, refreshToken) instead of a plain string
  • Aligned token handling to use IdentityTokenInfo pattern, matching the other two connectors

How has this been tested?

  • TypeScript type-check passes with no errors
  • Verified the fix matches the existing pattern in baseEvmConnector.ts and baseSolanaConnector.ts

Screenshots (if appropriate)

N/A

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

Checklist

  • My code follows the code style of this project. (run lint)
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

Note

Medium Risk
Touches authentication/session persistence for external wallet connectors by introducing cached/refreshable token storage and changing the token API surface; regressions could break login/rehydration or token lifecycle across connectors. Dependency bumps (Torus controllers/Auth/MetaMask kit) also increase integration risk.

Overview
Adds a new auth token info flow that replaces getIdentityToken/useIdentityToken with getAuthTokenInfo/useAuthTokenInfo across Modal + No-Modal SDKs and demo apps, standardizing on returning { idToken, accessToken?, refreshToken? }.

Implements external wallet session management in @web3auth/no-modal by introducing AuthSessionManager-backed token caching/refresh + best-effort logout cleanup, wiring it through connector init/connection events (including WalletConnect v2) and persisting tokens in core state (supports SSR token fetch).

Adds configurable token storage adapters (storage/cookieOptions) and exposes a Vue demo setting to select token storage, while updating dependencies to newer @toruslabs/*/@web3auth/auth versions and adding ox.

Reviewed by Cursor Bugbot for commit b232857. Bugbot is set up for automated code reviews on this repo. Configure here.

@hieu-w hieu-w requested review from a team as code owners April 1, 2026 05:47
@vercel
Copy link
Copy Markdown

vercel bot commented Apr 1, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
web3auth-web Ready Ready Preview, Comment Apr 5, 2026 7:22am

Request Review

@hieu-w hieu-w changed the title Feat/external wallet session management feat: external wallet session management Apr 1, 2026
Copy link
Copy Markdown
Member

@chaitanyapotti chaitanyapotti left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think we should use the AuthSessionManager to manage the session here and not write custom saving of tokens.

*/
// TODO: rename this to match customauth, sfa
storageType?: "session" | "local" | "cookies";
accessTokenProvider?: AccessTokenProvider;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think we dont need to pass it here

export type CONNECTOR_STATUS_TYPE = (typeof CONNECTOR_STATUS)[keyof typeof CONNECTOR_STATUS];

export type IdentityTokenInfo = { idToken: string };
export type IdentityTokenInfo = { idToken: string; accessToken?: string; refreshToken?: string };
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pls rename this key

apiClientConfig: { baseURL: citadelServerUrl(this.coreOptions.authBuildEnv) },
storage: this.coreOptions.storage,
cookieOptions: this.coreOptions.cookieOptions,
accessTokenProvider: this.coreOptions.accessTokenProvider,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think no need to pass


const idToken = await this.authSessionManager.getIdToken();
if (!idToken || checkIfTokenIsExpired(idToken)) {
return this.tryRefreshIdentityToken();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

idToken is never refreshed, it remains same for the entire session


try {
const response = await this.authSessionManager.ensureRefresh();
const refreshedIdToken = await this.authSessionManager.getIdToken();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

idtoken is never refreshed currently

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated

return this.state.idToken || null;
}

get accessToken(): string | null {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we need this ?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed it

"@toruslabs/loglevel-sentry": "^9.0.0",
"@toruslabs/metadata-helpers": "^8.2.0",
"@toruslabs/secure-pub-sub": "4.3.0",
"@toruslabs/session-manager": "^5.6.0",
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need this ? i think I exported everything from the auth package.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@arch1995 we miss AuthSessionManager, do we will export from auth sdk?

});

const idToken = await verifySignedChallenge(
const tokens: SiwwTokens = await verifySignedChallenge({
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey, I saw this usage in multiple places (baseSolanaConnector, walletConnectV2Connector).
Would be nice if we could refactor this to shared func/method

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated

Copy link
Copy Markdown

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit e46b571. Configure here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants