Overview
useSwitchAccount switches the active session to a different stored account. It clears the current auth state, sets the target account as active, and fetches a fresh access token using the stored refresh token.
Usage Example
Parameters
The hook returns aswitchAccount function that accepts:
The ID of the account to switch to. Must be present in the stored accounts map.
Returns
Async function that switches the active session. Calling it with the ID of
the already-active account is a no-op. Throws synchronously if the account is
not found or no
projectId is available. Runtime errors (e.g. token refresh
failure) are caught and surfaced via the error field instead of throwing.true while the switch is in progress (clearing state and fetching a new
access token).Error message if the switch failed, or
null if no error occurred.
