Skip to main content
Sublay supports up to 5 simultaneously stored accounts in a single app instance. Users can add new accounts, switch between them, and remove individual accounts without losing session data for the others.

Architecture

Each signed-in account is stored in the Redux accounts map, keyed by user ID. The map persists to localStorage (web) or platform-specific secure storage (React Native). The activeAccountId field tracks which account is currently active. When the user switches accounts, the SDK restores the stored refresh token for the target account and fetches a new access token automatically.

Hooks

Reading Account State

Each account entry in accounts is an AccountSummary containing id, name, email, and avatar.

Adding a New Account

Calling addAccount clears the current auth state, which causes the app to display the sign-in UI. The previously stored accounts remain in the accounts map and are not affected. After the user signs in to the new account, it is added to the map automatically.
canAddAccount is false when the maximum of 5 accounts is already stored.

Switching Accounts

Switching is asynchronous. The SDK revokes the current access token, sets the target account as active, and fetches a fresh access token using the stored refresh token.

Removing an Account

When the removed account is the currently active one, the SDK automatically switches to the next available account. If no other accounts remain, the SDK resets to the unauthenticated state. Removing an account also sends a best-effort sign-out request to the server to revoke the refresh token family.

Signing Out All Accounts

signOutAll sends a sign-out request for every stored account’s refresh token (best-effort) and clears all local auth state.

See Also