Skip to main content
Manages the authentication state and access token for standard CDP authentication (email/SMS/OAuth flows).

Implements

Constructors

Constructor

Initializes the token manager.

Parameters

Returns

AuthManager

Methods

getUser()

Gets the current user, or null if there is no user signed in.

Returns

| null | User The current user.

Implementation of

IAuthManager.getUser

isSignedIn()

Returns whether the user is signed in - i.e., whether there is an unexpired access token and user. Attempts to refresh the token if it’s expired.

Returns

Promise<boolean> True if the user is signed in, false otherwise.

Implementation of

IAuthManager.isSignedIn

signOut()

Signs out the user, clearing all authentication state.

Returns

Promise<void>

Implementation of

IAuthManager.signOut

addAuthStateChangeCallback()

Adds a callback to be called when the auth state changes.

Parameters

Returns

void

Implementation of

IAuthManager.addAuthStateChangeCallback

getToken()

Gets the access token, refreshing it if it is expired. Returns null if the user is not signed in.

Parameters

Returns

Promise<null | string> The access token.

Implementation of

IAuthManager.getToken

getTokenExpiration()

Gets the expiration time of the access token, or null if the user is not signed in.

Returns

Promise<null | number> The expiration time of the access token.

Implementation of

IAuthManager.getTokenExpiration

getWalletSecretId()

Gets the currently registered wallet secret ID. Rejects if the user is not signed in.

Returns

Promise<string> The wallet secret ID.

Implementation of

IAuthManager.getWalletSecretId

getXWalletAuth()

Gets the X-Wallet-Auth header. Rejects if the user is not signed in.

Parameters

Returns

Promise<string> The X-Wallet-Auth header.

Implementation of

IAuthManager.getXWalletAuth

getAuthState()

Gets the authentication state.

Returns

| null | AuthState The authentication state.

Implementation of

IAuthManager.getAuthState

setAuthState()

Sets the authentication state.

Parameters

Returns

Promise<void>

Implementation of

IAuthManager.setAuthState

clearAuthState()

Clears the authentication state.

Returns

Promise<void>

Implementation of

IAuthManager.clearAuthState

ensureInitialized()

Ensures the AuthManager is initialized before proceeding. If initialization is already in progress, waits for it to complete.

Returns

Promise<void>

Implementation of

IAuthManager.ensureInitialized

_doInitialize()

Internal async initialization logic.

Returns

Promise<void>

shouldRefreshToken()

Returns whether the token should be refreshed.

Returns

boolean True if the token should be refreshed, false otherwise.

refreshAccessToken()

Refreshes the access token and transitions the auth state accordingly. If a refresh is already in progress, it will wait for that refresh to complete. Retries with exponential backoff on transient failures only. Unauthorized error short-circuit immediately since retrying won’t help.

Parameters

Returns

Promise<void> The new access token.

scheduleTokenRefresh()

Schedules a token refresh to occur exactly when shouldRefreshToken() would return true. Uses the same REFRESH_CREDENTIALS_BUFFER_MS timing as the rest of the auth system.

Returns

void

cancelTokenRefresh()

Cancels any scheduled token refresh.

Returns

void

Properties