Skip to main content
Sublay’s built-in authentication lets you register and sign in users with an email address and password without building your own auth backend. The SDK’s useAuth hook exposes all the actions you need.

Sign Up

Call signUpWithEmailAndPassword with at minimum an email and password. Additional profile fields are optional.

Optional Profile Fields

You can pass additional profile data at registration time:
If you supply both avatar (URL) and avatarFile (file upload), the file takes precedence and the URL is ignored.

Sign In

Require Email Verification

Turn on Require email verification before sign-in (Dashboard → Settings → SDK) to make users confirm their email before they can sign in. With it on:
  • Sign-up creates no session. It emails a confirmation link (or a 6-digit code) that lasts 24 hours, and resolves { emailVerificationRequired: true } instead of signing the user in. It answers the same way whether or not the email already has an account; an existing account’s owner gets an email pointing them to sign-in or password reset instead.
  • Accounts with a password must confirm their email before any sign-in — with the password, through any OAuth provider, and on token refresh. A refused sign-in sends a new confirmation email, unless one went out in the last 10 minutes.
  • Users already signed in with an unconfirmed email lose access within 30 minutes: their next token refresh is refused, so their API calls fail. useAuth().user stays set until the app next starts (or switches to that account), when the SDK signs them out and marks the account as needing sign-in.
  • Not affected: accounts with no password that sign in only through a provider, and users of your own login (external sign-in).
  • The setting applies to the v7 and v8 APIs. v7 sign-up is refused while it’s on, so sign users up through v8.
Users who never confirmed and whose email can’t receive mail won’t be able to sign in once it’s on.

Sign up

Pass emailVerification to choose how the email is sent. mode: "link" (the default) emails a Confirm my email button that sends the user on to redirectUrl (which must be on your Verified Domains, like link mode below). mode: "code" emails a 6-digit code and resolves a verificationId to confirm it with:
Then confirm the code with useVerifyEmail, and sign the user in:
A code allows 5 wrong tries. If the user loses the code, runs out of tries, or a correct code is refused (for example after signing up twice, when the second answer carries an ID that doesn’t match the emailed code), the user signs in again. Within 10 minutes of the last confirmation email, that sends nothing new and returns the verificationId of the code already sent; after that, or once a code has run out of tries, it can send a new code with a new verificationId. Emails to one address are limited to one every 10 minutes and five a day; past the limit, nothing is sent and the code already in the inbox keeps working.

Sign in

A correct password on an unconfirmed account throws an Error whose code is auth/email-not-verified, and a new confirmation email is sent (unless one went out in the last 10 minutes). Pass the same emailVerification to sign-in to choose link or code (left out, it uses what the user chose at sign-up, else a link). In code mode the error carries verificationId:
A wrong password or unknown email still gets the one “incorrect email or password” answer, so the new error only appears after a correct password. A password reset also confirms the email.
With the setting on, sign-up doesn’t tell a new email from a registered one, but sign-in can: someone who signs up with an address and then signs in with the same made-up password is told “confirm your email” when sign-up created the account, and “incorrect password” when it already existed. A username sent with the sign-up shows it too: it’s taken afterwards only if sign-up created the account. With the setting off, sign-up’s 409 reports a registered email directly.
A user’s own connected sign-ins are kept by a password reset. To remove a connection they don’t recognise, use useOAuthIdentities to list and unlink it.

The Account Limit

A device stores at most 5 accounts (Multi-Account). Both calls above refuse a sixth, throwing an Error whose message is exported as ACCOUNT_LIMIT_MESSAGE:
Sign-in is deliberately checked after the network call. Comparing the typed email against the stored accounts first would be faster and wrong: it would refuse users whose stored email is out of date, absent, or capitalised differently, with no way through.
One sign-up case does leave a user record behind. The pre-request check can only use the accounts stored when the call left. If the fifth slot fills while your sign-up is in flight — another tab, or a second sign-in racing this one — the account has already been created on the server by the time the limit is discovered. The SDK signs that session straight back out, but the user record persists, so retrying the same email after freeing a slot fails with “email already in use”. Sign in with it instead.
A sign-up that resolves { emailVerificationRequired: true } creates no session, so it is only checked before the request. A refusal leaves the currently active account signed in, leaves the accounts map untouched, signs the server-side session created by the refused attempt back out, and sets accountLimitReached — see Reaching the account limit.

Sign Out

signOut revokes the current session’s entire token family on the server and clears local auth state. Once this device has a stored push identifier it also asks the server to unbind that account’s push notifications, in the same transaction as the session teardown.
signOut rejects when the server refuses that unbind, and in that case nothing was torn down on either side — the session survives so the user can retry. Its signature is () => Promise<void>, so nothing warns you at compile time; without the catch the rejection is unhandled and your UI reports a sign-out that did not happen. 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. See useAuth.

Change Password

Users who signed up with email/password can change their password while authenticated. The current password must be provided for verification. A password change ends every other session for that user, so their other devices must sign in again with the new password. The session making the call survives — the server reads which session is asking off the access token the request already carries, so nothing extra is sent. It also removes that user’s push bindings on every other device while keeping this one’s, which the hook arranges by sending the device identifier it already holds. See useAuth and Change Password.

Password Reset

Users who forget their password can request a reset email. Sublay sends a link to the registered email address. The link expires after 1 hour. Completing the reset revokes every session for that user and removes every push binding they hold, on every device — including the one they are standing on. They sign in again everywhere, and each device re-binds for push on its own once it is next opened. The reset itself is completed by the page the link points to, which collects the new password and calls the Reset Password endpoint — there is no React hook for that step.
The API gives the same answer (204, no body) whether or not the email address is registered, to prevent user enumeration.

Auth State

Check whether the SDK has finished initializing and whether a user is currently signed in:

Email Verification

After sign-up, you can prompt users to verify their email address. Sublay sends a short-lived token (5 minutes) via email. There are two delivery modes: a code the user types back into your app, or a link they click to verify automatically.

Send a verification email

mode is always required, and it determines what else you need to pass:
TypeScript enforces this combination at compile time — sendVerificationEmail({ mode: "code" }) (missing tokenFormat) or sendVerificationEmail({ mode: "code", tokenFormat: "hex", tokenLength: 6 }) won’t type-check.

Verify with a code

When using mode: "code", collect the token from the user and call useVerifyEmail:
On success, user.isVerified is updated immediately in the local Redux store — no refetch needed. When using mode: "link", the email contains a button that opens a Sublay page asking the user to confirm (so an email scanner opening the link verifies nothing). When they click Confirm my email, the email is verified and they see a success page that either:
  • sends them on to the redirectUrl you provided, with verified=true added, after 5 seconds, or
  • stays on the success page if no redirectUrl was given.
redirectUrl must be on one of your project’s Verified Domains (Dashboard → Settings → Domains), the same list that lets your web app call Sublay from a browser. Each entry is matched exactly: example.com doesn’t cover www.example.com, so list the exact host of the page users land on. A mobile app with no website listed there either adds the domain of the page it wants users to land on, or leaves redirectUrl out (or uses mode: "code"). Custom-scheme deep links such as myapp://verified are refused. See Send Verification Email for the matching rules. The user.isVerified field will be true the next time the user’s session is loaded (e.g. on next sign-in or token refresh). There is no SDK callback for link-mode verification since it happens outside the app’s JS context.
The verification token is valid for 5 minutes and can only be used once. Calling sendVerificationEmail while a previous token is still valid will generate a new token — the old one remains valid until it expires or the new one is used.

See Also