Overview
useAuth is the primary authentication hook. It returns current token state and functions for all built-in auth operations: sign-up, sign-in, sign-out, password change, setting an initial password, and manual token refresh.
Usage Example
Returns
useAuth returns an object with the following fields:
true once the SDK has attempted to restore a session from the stored refresh
token. Always check this before rendering auth-dependent UI.The current JWT access token, or
null if no user is signed in. Expires every
30 minutes; the SDK refreshes it automatically.Manually set a refresh token in Redux state. Useful when integrating external
auth flows that hand tokens directly to the SDK.
Create a new account and sign in. Accepts a
SignUpWithEmailAndPasswordProps
object. Declared (props) => Promise<{ emailVerificationRequired: true; verificationId?: string } | void>:
it resolves nothing when the user is signed in, and
{ emailVerificationRequired: true, verificationId? } when the project
requires email verification before sign-in — then no session is created and
nothing is stored; the user signs in after confirming their email
(verificationId is present in code mode, for
useVerifyEmail). Throws if registration
fails: the thrown Error (typed SublayAuthError) has the server’s error
text as its message, the server’s code, and param when the server names
the failing input — for example code: "auth/username-taken" with
param: "username", or auth/email-taken with param: "email".Parameters:email(required) — User’s email addresspassword(required) — Passwordname(optional) — Display name,string | null(nullis the same as leaving it out)username(optional) — Unique usernameavatar(optional) — Avatar URL,string | null(nullis the same as leaving it out)bio(optional) — Bio text,string | null(nullis the same as leaving it out)location(optional) —{ latitude, longitude }birthdate(optional) — Date of birth: aDate, or a full UTC timestamp string such as"1990-05-17T00:00:00.000Z"(a date alone, like"1990-05-17", is refused)metadata(optional) — Public custom fieldssecureMetadata(optional) — Custom fields no API response returns, the user’s own included. The user can write them but not read them back, so don’t store anything your app needs to trust.avatarFile(optional) — Avatar image to upload:{ file, options }, wherefileis aFile,Blobor React Native file{ uri, name, type? }andoptionsthe image processing options (moderequired). Sends the sign-up asmultipart/form-databannerFile(optional) — Banner image to upload, same shape asavatarFileemailVerification(optional) —{ mode?: "link" | "code"; redirectUrl?: string | null }: how the confirmation email is sent when the project requires email verification before sign-in. Ignored otherwise. See Require Email Verification.
ACCOUNT_LIMIT_MESSAGE when the device
already stores 5 accounts. Normally this happens before any network call, so
no account is created — but if the fifth slot fills while the request is in
flight, the refusal lands after it and the created user record persists.Sign in with an existing account. Accepts
{ email: string; password: string; emailVerification?: { mode?: "link" | "code"; redirectUrl?: string | null } }.
Throws if credentials are invalid. The thrown Error (typed SublayAuthError)
has the server’s error text as its message and carries the server’s
code (and param when the server names the failing input):
auth/invalid-credentials for a wrong email or password,
auth/email-not-verified when the password is
correct but the project requires email verification before sign-in and the
email isn’t confirmed — a new confirmation email is sent (unless one went out in the last 10 minutes),
the way emailVerification says, and in code mode the error also carries
verificationId. Also throws
ACCOUNT_LIMIT_MESSAGE if this would be a sixth
account on the device. Signing back in to an account already stored on the
device always succeeds, even at the limit.Sign out the current account. Sends a sign-out request to the server to revoke
the refresh token family — and, once this device has a stored push identifier, to
unbind that account’s notifications in the same transaction — then clears
local auth state.It rejects only when the server refuses the unbind. In that case nothing is
torn down locally either: the account keeps its entry and its credential so the
user can retry, rather than being left receiving notifications from an account
they can no longer reach. Every other failure — no network, a throttled or
otherwise rejected request, a device that never registered for push — still
signs out locally, because a user must always be able to sign out.It does not sign you into another account. If other accounts are stored,
they stay in the map but none is activated — see
Multi-Account.
Change the password for the currently authenticated user. Accepts
{ password: string; newPassword: string }. The current password must be
correct. Throws if verification fails.Every other session for that user ends, and the caller’s does not. The
access token the request is authenticated with names the session it was minted
from, so the server knows which one is asking and nothing extra is sent. The
user stays signed in where they are standing; every other device must sign in
again with the new password.It also clears that user’s push bindings on every other device, and keeps
this one’s. The hook sends the device identifier it already holds, which is
what lets the server single out the calling handset and spare exactly its
binding — so notifications keep arriving where the user is standing, and stop
on the devices they just locked out. Nothing re-binds a device from its live
session, so the others stay quiet until each is next opened. On a device that
has never registered for push there is no identifier to send and no binding to
keep, and every one of the user’s bindings goes. See
Change Password.Only this user’s sessions are ended. Other accounts stored on this device
belong to other users and are untouched. The mirror case is the one to plan
for: when this user changes their password somewhere else, the copy of their
account stored here as a background account dies — and a stored account killed
that way still has a valid-looking expiry, so it is only discovered by trying,
which is what needsReauth on
useAccounts
records.An access token minted before the change keeps working until it expires, up to
30 minutes, so “other devices no longer work” is about their refresh, not their
next request.Set an initial password for an OAuth-only user who has no password yet.
Accepts
{ newPassword: string }. Unlike changePassword, there is no
current password to verify. Throws if the user already has a password
(auth/already-password-authenticated) — use changePassword in that case.Manually trigger an access token refresh using the stored refresh token.
Declared
() => Promise<string>: it resolves with the new access token and
rejects on every path that cannot produce one — a failed refresh, no
stored refresh token to present, or no projectId. It never resolves
undefined. The underlying requestNewAccessTokenThunk rejects in the same
cases, so fulfilled.match(result) is false when no refresh token is
present. The SDK handles refresh
automatically in most cases; use this only when you need to force a refresh.This refreshes the active account only — it presents whatever refresh
token is in auth state. Switching to a stored account no longer goes through
this thunk: switchAccount exchanges the target’s credential out of band,
before it touches the live session, so it cannot disturb the account you are
currently signed into. If you were observing auth/requestNewAccessToken
actions to detect account switches, watch the accounts slice instead. See
When a transition fails.The Account Limit
A device stores at most 5 accounts.signUpWithEmailAndPassword and signInWithEmailAndPassword reject when a sixth would be added, throwing an Error whose message is exported as ACCOUNT_LIMIT_MESSAGE:
- Sign-up is normally refused before the network call; sign-in is refused after it, because only the server can say which account the credentials belong to. That is deliberate — checking the typed email against the stored accounts would lock users out of their own account whenever the stored email is stale, absent or cased differently. (A sign-up whose fifth slot fills mid-request is refused afterwards, and that user record does persist — see what a refusal leaves behind.)
- A refused sign-in leaves the currently active account signed in. Nothing is torn down, the accounts map is untouched, and the session the server created for the refused attempt is signed back out, so nothing is left dangling.
accountLimitReached on useAccounts and useAddAccount. That flag is the only channel on the OAuth paths, which cannot reject their caller — see Reaching the account limit.
Controlling Error Logging
Handled SDK failures are logged withconsole.error. To change or silence that:
SublayProvider prop because the setting is process-global — a prop would be silently last-mount-wins in an app that mounts two providers. It is coarse by design: it silences all SDK logging, including unexpected failures. Errors are still returned to the calling hooks; only the console output changes.

