Skip to content

Feat: sdk v11 hooks#139

Merged
chaitanyapotti merged 11 commits into
masterfrom
feat/sdk-v11-hooks
Jul 21, 2026
Merged

Feat: sdk v11 hooks#139
chaitanyapotti merged 11 commits into
masterfrom
feat/sdk-v11-hooks

Conversation

@tuna1207

@tuna1207 tuna1207 commented Jul 15, 2026

Copy link
Copy Markdown
Member

Motivation and Context

This PR brings the React Hooks integration in line with Web3Auth SDK v11 session/auth APIs and dashboard-driven project configuration. Hooks consumers need clearer separation between connected (wallet/session keys) and authorized (citadel access token), plus hooks for token info and session refresh. It also aligns analytics, account abstraction (including EIP-7702), and setup docs with the rest of the v11 SDK surface.

Jira Link: https://consensyssoftware.atlassian.net/browse/EMBED-399

Description

React Hooks

  • Extend Web3AuthProvider / useWeb3Auth() with isAuthorized and accessToken, distinguishing citadel-authorized sessions from SFA-connected sessions.
  • Add syncSessionState() to rehydrate provider, MFA flag, and access token after init, connect, MFA, or refresh.
  • Add useAuthTokenInfo and useRefreshSession hooks.
  • Update useAccessToken to read/write shared context state (accessToken; token kept as deprecated alias).
  • Deprecate useIdentityToken / getIdentityToken() in favor of useAuthTokenInfo / getAuthTokenInfo().
  • Update useEnableMFA and useManageMFA to sync session state after redirect flows.
  • Default loginSource to "web3auth-react-native" in useWeb3AuthConnect.
  • Tag hooks usage with integration_type: "React Hooks" in analytics.

Core SDK

  • Refactor analytics: structured error_code / error_message, richer initialization properties (CAIP chain IDs, RPC hostnames, AA/wallet-services config), and connection failure tracking.
  • Add disableAnalytics and enableAnalyticsInDev init options.
  • Load sessionTime from dashboard project config (fallback: 86400).
  • Pass aa_provider when fetching project config; support externalWalletAuth in auth payloads.
  • Account abstraction: EIP-7702 smart account validation, skip ERC-4337 provider wrapping for 7702, derive useAAWithExternalWallet from dashboard walletScope.
  • Extract clearLocalSessionState() for logout and failed session refresh.
  • Add wallet UI option enableDefiPositionsDisplay and defaultPortfolio: "defi".
  • Fix MFA management analytics (MFA_MANAGEMENT_SELECTED / MFA_MANAGEMENT_COMPLETED).

Metro & docs

  • Add MessageEvent polyfill in global-shim.js for Hermes (@web3auth/auth postMessageStream).
  • Major README update: Node 22+ / npm 10+, Metro withWeb3Auth setup, entry setup import, bare/Expo redirect URL configuration, and analytics documentation.
  • Update bare and Expo hooks demo apps to exercise the new APIs.

How has this been tested?

Screenshots (if appropriate):

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.
  • My code requires a db migration.

Note

Low Risk
Changes are documentation and sample-app only; no production SDK logic in this diff.

Overview
Documentation is expanded for v11 onboarding: Node/npm requirements, bare vs Expo dependency installs, Metro withWeb3Auth wrapping, mandatory @web3auth/react-native-sdk/setup as the first import, redirect URL / whitelist guidance (including Expo Go vs standalone), and a new analytics section (disableAnalytics, buildEnv, tracked events).

Integration examples move from login / OPENLOGIN_NETWORK to init() + connectTo() with WEB3AUTH_NETWORK, EncryptedStorage / SecureStore, and updated redirect schemes. The bare hooks demo adds the setup import and exercises v11 session APIs: isAuthorized / accessToken from useWeb3Auth(), useAccessToken, useAuthTokenInfo, and useRefreshSession (replacing useIdentityToken in that sample). Sample app links now point at the demo folder.

iOS lockfile for the bare hooks example picks up RNCAsyncStorage and refreshed pod checksums (CocoaPods 1.16.2).

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

@cursor cursor Bot left a comment

Copy link
Copy Markdown

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 21f83dd. Configure here.

Comment thread demo/rn-bare-hooks-example/App.tsx Outdated
Comment thread src/base/analytics.ts
Comment thread src/base/analytics.ts
Comment thread src/react/hooks/useAccessToken.ts
Comment thread src/react/context/web3AuthInnerContext.ts
Comment thread src/react/hooks/useEnableMFA.ts
Comment thread src/react/hooks/useManageMFA.ts
Comment thread src/types/interface.ts Outdated
Comment thread src/utils.ts Outdated
Comment thread src/base/analytics.ts Outdated
private enableAnalyticsInDev: boolean = false;

constructor(options: AnalyticsOptions = {}) {
this.enableAnalyticsInDev = Boolean(options.enableAnalyticsInDev);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

rename this pls. choose based on buildEnv

Comment thread src/metro/global-shim.js Outdated

// Minimal MessageEvent polyfill for @web3auth/auth postMessageStream, which reads
// MessageEvent.prototype at module-load time (Hermes has no browser MessageEvent global).
if (typeof global.MessageEvent === "undefined") {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

this won't load right..
can we patch web3auth/auth to not load at build time?

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 tested, this works, or by load do you mean the package @web3auth/auth doesn't load ?

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.

we can fix upstream @web3auth/auth

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.

here is the patch PR for @web3auth/auth
Web3Auth/Auth#402

@chaitanyapotti
chaitanyapotti merged commit 126752f into master Jul 21, 2026
1 check passed
@chaitanyapotti
chaitanyapotti deleted the feat/sdk-v11-hooks branch July 21, 2026 09:28
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.

3 participants