Documentation Index
Fetch the complete documentation index at: https://docs.cloud.coinbase.com/llms.txt
Use this file to discover all available pages before exploring further.
Manages the authentication state and access token for standard CDP authentication
(email/SMS/OAuth flows).
Implements
Constructors
Constructor
new AuthManager(projectId: string): AuthManager;
Initializes the token manager.
Parameters
| Parameter | Type | Description |
|---|
projectId | string | The project ID. |
Returns
AuthManager
Methods
getUser()
getUser():
| null
| User;
Gets the current user, or null if there is no user signed in.
Returns
| null
| User
The current user.
Implementation of
IAuthManager.getUser
isSignedIn()
isSignedIn(): Promise<boolean>;
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()
signOut(): Promise<void>;
Signs out the user, clearing all authentication state.
Returns
Promise<void>
Implementation of
IAuthManager.signOut
addAuthStateChangeCallback()
addAuthStateChangeCallback(callback: OnAuthStateChangeFn): void;
Adds a callback to be called when the auth state changes.
Parameters
| Parameter | Type | Description |
|---|
callback | OnAuthStateChangeFn | The function to call when the auth state changes. |
Returns
void
Implementation of
IAuthManager.addAuthStateChangeCallback
getToken()
getToken(options?: {
forceRefresh?: boolean;
}): Promise<null | string>;
Gets the access token, refreshing it if it is expired. Returns null if the user is not
signed in.
Parameters
| Parameter | Type | Description |
|---|
options? | { forceRefresh?: boolean; } | The options for getting the token. |
options.forceRefresh? | boolean | Whether to force a refresh of the token. |
Returns
Promise<null | string>
The access token.
Implementation of
IAuthManager.getToken
getTokenExpiration()
getTokenExpiration(): Promise<null | number>;
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()
getWalletSecretId(): Promise<string>;
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()
getXWalletAuth(options: {
requestMethod: string;
requestHost: string;
requestPath: string;
requestData?: Record<string, unknown>;
}): Promise<string>;
Gets the X-Wallet-Auth header. Rejects if the user is not signed in.
Parameters
| Parameter | Type | Description |
|---|
options | { requestMethod: string; requestHost: string; requestPath: string; requestData?: Record<string, unknown>; } | The options for the request. |
options.requestMethod | string | The HTTP method of the request. |
options.requestHost | string | The host of the request. |
options.requestPath | string | The path of the request. |
options.requestData? | Record<string, unknown> | The data of the request. |
Returns
Promise<string>
The X-Wallet-Auth header.
Implementation of
IAuthManager.getXWalletAuth
getAuthState()
getAuthState():
| null
| AuthState;
Gets the authentication state.
Returns
| null
| AuthState
The authentication state.
Implementation of
IAuthManager.getAuthState
setAuthState()
setAuthState(authState: AuthState): Promise<void>;
Sets the authentication state.
Parameters
| Parameter | Type | Description |
|---|
authState | AuthState | The authentication state. |
Returns
Promise<void>
Implementation of
IAuthManager.setAuthState
clearAuthState()
clearAuthState(): Promise<void>;
Clears the authentication state.
Returns
Promise<void>
Implementation of
IAuthManager.clearAuthState
ensureInitialized()
ensureInitialized(): Promise<void>;
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()
protected _doInitialize(): Promise<void>;
Internal async initialization logic.
Returns
Promise<void>
shouldRefreshToken()
protected shouldRefreshToken(): boolean;
Returns whether the token should be refreshed.
Returns
boolean
True if the token should be refreshed, false otherwise.
refreshAccessToken()
protected refreshAccessToken(trigger: string): Promise<void>;
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
| Parameter | Type | Default value | Description |
|---|
trigger | string | "on_demand" | The trigger for the refresh. |
Returns
Promise<void>
The new access token.
scheduleTokenRefresh()
protected scheduleTokenRefresh(): void;
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()
protected cancelTokenRefresh(): void;
Cancels any scheduled token refresh.
Returns
void
Properties
| Property | Modifier | Type | Default value |
|---|
projectId | protected | string | undefined |
authState | protected | | null | AuthState | null |
walletSecret | protected | | null | WalletSecret | null |
authStateChangeCallbacks | protected | OnAuthStateChangeFn[] | [] |
initPromise | protected | null | Promise<void> | null |
refreshTimeout | protected | null | Timeout | null |