Documentation Index
Fetch the complete documentation index at: https://www.dynamic.xyz/docs/llms.txt
Use this file to discover all available pages before exploring further.
waitForAuthSuccess
Returns a promise that resolves with the authenticated user once theauthSuccess event fires. Use this when you need to ensure authentication is fully complete — including MFA and other intermediate steps — before proceeding (for example, before loading wallets or accessing user data).
Before this: set up the Dynamic client (see Setting up the Dynamic Client).
Why use this instead of listening to events?
Listening forauthSuccess with dynamicClient.auth.on works, but it requires manual cleanup and doesn’t handle edge cases like MFA flows where authentication pauses for user input. waitForAuthSuccess wraps this into a single promise that:
- Resolves when authentication completes (even after MFA or other intermediate steps)
- Rejects when authentication fails or is cancelled
- Supports an optional timeout
Usage
Parameters
| Parameter | Type | Description |
|---|---|---|
timeout | number | Maximum time in milliseconds to wait. Rejects with an error if exceeded. |
Returns
Promise<UserProfile> — Resolves with the authenticated user profile.
Behavior
- User not yet authenticated: Listens for
authSuccessand resolves when it fires. IfauthFailedfires first, the promise rejects. - User already authenticated: Waits briefly (500 ms grace period) for an incoming
authSuccessevent. If no event arrives, resolves with the current authenticated user. This handles the case where authentication completed moments before the call. - Timeout: If
timeoutis set and neitherauthSuccessnorauthFailedfires within that window, the promise rejects with a timeout error.
Examples
Wait for authentication before loading wallets
- With UI auth flow
- With email OTP
React Native
Error handling
The promise rejects in three cases:| Scenario | Error message |
|---|---|
| User cancels authentication | Authentication was cancelled by the user |
| Authentication fails | Authentication failed: <reason> |
| Timeout exceeded | waitForAuthSuccess timed out |
Related
- Listening to events — Subscribe to individual client events
- Auth module events — Full list of auth events including
authSuccessandauthFailed - MFA — MFA flows that complete before
authSuccessfires