Skip to main content
The JavaScript SDK gives you full control over step-up authentication without any UI framework. Works with vanilla JS, React, Vue, Svelte, Angular, or any other setup. For concepts, scopes, and token lifecycle, see Step-up authentication overview.

Prerequisites

  • @dynamic-labs-sdk/client initialized
  • At least one verification method enabled in your dashboard security settings
  • Step-up authentication enabled for your environment

Quick start

The pattern is always: check → verify → proceed. After verification, the elevated access token is automatically stored and applied to subsequent Dynamic API calls. You never need to manually handle the token.
checkStepUpAuth is the recommended way to determine whether step-up is required. It performs a fast local check first (if a valid elevated token already exists, it returns immediately without an API call), then falls back to a server-authoritative check that evaluates your environment configuration, SDK version, MFA settings, and action-based MFA requirements. On failure, it defaults to { isRequired: true } for safety.
The response type:

Checking for a valid token (alternative)

checkStepUpAuth (shown above) is the recommended approach. It combines the token check with credential discovery in a single call. Use hasElevatedAccessToken only if you need a simple synchronous local-only check.
Use hasElevatedAccessToken to check if the user already has a non-expired elevated token for a scope:

Verification methods

Pass requestedScopes to any verification method. After success, the elevated token is automatically stored and applied to Dynamic API calls.

Choosing the right method

The JavaScript SDK requires you to choose which verification method to present. checkStepUpAuth returns all available credentials — both MFA (passkey, TOTP) and re-auth (email, SMS, OAuth, wallet) — so you can route the user to the right method in a single call:
When a user has MFA methods registered, the backend requires MFA for elevated token issuance — re-auth credentials won’t be returned. checkStepUpAuth handles this automatically, so you don’t need separate logic for MFA vs. re-auth users.
In React, drive each authentication step with its hook — useCheckStepUpAuth (or call checkStepUpAuth inside a handler), useAuthenticatePasskeyMFA, useAuthenticateTotpMfaDevice, useSendEmailOTP, and useVerifyOTP — and use useState to track which verification UI to show. The flow mirrors the full example below.

Full example: wallet export with method selection

Error handling

Verification methods throw when the user cancels or verification fails:
Common error scenarios:
  • User cancels the browser passkey prompt
  • Invalid OTP code entered
  • MFA device verification timeout
  • Network error during verification

Available scopes

See the complete scopes reference for all supported values.

External auth (Bring Your Own Auth)

If you use external auth (BYOA), your backend can issue elevated access tokens directly — no user interaction required. See the External Auth Step-Up guide.
Last modified on June 24, 2026