Skip to main content
The auth module handles user authentication flows server-side. This is useful for custom onboarding pipelines, admin-initiated account creation, token introspection, and password management.
All auth functions operate on behalf of your project. The caller is your server, authenticated via API key — not an end user.
Changing or setting a password, self-service account deletion, and linking or listing OAuth identities need the user’s own access token: a service key is refused (403 auth/user-token-required or oauth/user-token-required), so this SDK has no functions for them. Call them from your client with the user’s session. To delete an account from your server, use users.deleteUser.

signUp

Creates a new user account and returns credentials.
string
required
The user’s email address.
string
required
The user’s plain-text password (hashed server-side).
string | null
Display name for the user. null or an empty string leaves it unset.
string
Unique username. Must be available — check with users.checkUsernameAvailability first.
string | null
Avatar image URL, stored as given. Separate from avatarFile, which uploads an image.
string | null
Bio text. null or an empty string leaves it unset.
{ latitude: number; longitude: number }
The user’s location, stored as a GeoJSON point.
string | Date
The user’s birthdate: a Date, or a full UTC timestamp string such as "1990-05-17T00:00:00.000Z". A date alone ("1990-05-17") or a time with an offset is refused with 400 auth/invalid-body and param: "birthdate".
object
Arbitrary key-value data attached to the user at creation time.
object
Key-value data no API response returns to any user. Users can also write their own, so don’t treat it as trusted.
{ mode?: "link" | "code"; redirectUrl?: string | null }
How the confirmation email is sent when the project requires email verification before sign-in. mode defaults to "link"; "code" emails a 6-digit code and returns a verificationId. redirectUrl (link mode) must be on the project’s Verified Domains. Ignored when the setting is off. See Sign Up.
{ file: Uint8Array | Blob; filename?: string; mimeType?: string; options: ImageOptions }
An avatar image to upload, up to 50 MB. Raw bytes carry no type, so pass mimeType with a Uint8Array (image/jpeg, image/png or image/webp; without it the file goes as application/octet-stream and is refused with 400 auth/unsupported-file-type); a Blob keeps its own type. options says how to process the image and must include mode (see Upload Image). With an image, the request is sent as multipart/form-data.
{ file: Uint8Array | Blob; filename?: string; mimeType?: string; options: ImageOptions }
A banner image to upload; same shape as avatarFile.
Returns — Promise<SignUpResponse | EmailVerificationRequiredResponse>: { success: true, user, accessToken, refreshToken }, or, when the project requires email verification before sign-in, { success: true, emailVerificationRequired: true, verificationId? } with no tokens.

signIn

Authenticates an existing user and returns fresh credentials.
string
required
The user’s email address.
string
required
The user’s password.
{ mode?: "link" | "code"; redirectUrl?: string | null }
How the new confirmation email is sent when sign-in is refused because the account’s email isn’t confirmed. Ignored when the project doesn’t require email verification before sign-in.
Returns — Promise<{ success: true; user: AuthUser; accessToken: string; refreshToken: string }> (see AuthUser) When the project requires email verification before sign-in and the account’s email isn’t confirmed, a correct password rejects with a 403 whose body is EmailNotVerifiedErrorBody ({ error, code: "auth/email-not-verified", verificationId? }, read from err.response.data), and a new confirmation email is sent (unless one went out in the last 10 minutes).

signOut

Invalidates a refresh token, ending the user’s session.
string
required
The refresh token to invalidate.
PushDeviceIdentifier
Optional. The device the user is signing out on — { platform: "ios" | "android", token } or { platform: "web", subscription }. When supplied (and the project has the push bundle), the server deletes that user’s push binding for the device in the same transaction as the sign-out. Omit it and the sign-out revokes the token family only, leaving any push binding in place.
If the unbind fails, nothing is committed — the call rejects with 500 / auth/device-deregistration-failed and the session survives so you can retry. Never treat a failed signOut as signed out; discarding the credential anyway leaves the user receiving notifications from an account they can no longer reach.A 200 carrying auth/push-unbind-status-unknown is a success, not a failure: the server signed the user out without attempting an unbind because it could not determine whether the project has push devices. See POST /auth/sign-out.
Returns — Promise<SignOutPushUnbindSkipped | null>: null when signed out (204), or { pushUnbindSkipped: true, code: "auth/push-unbind-status-unknown", message } (200) when signed out without the requested push unbind.

requestNewAccessToken

Exchanges a valid refresh token for a new access token. The refresh token rotates: store the returned refreshToken in place of the one you sent.
string
required
A valid, non-expired refresh token.
Returns — Promise<RequestNewAccessTokenResponse>: { success: true, accessToken, refreshToken, user: AuthUser }, or { user: null, accessToken: null } when refreshToken is empty.

verifyExternalUser

Verifies a signed JWT representing an externally-authenticated user and returns Sublay credentials. Use this when your application manages its own auth and you want to associate users with Sublay.
string
required
A JWT signed with your project’s signing secret, containing user identity claims.
Returns — Promise<{ success: true; user: AuthUser; accessToken: string; refreshToken: string }> (see AuthUser)

requestPasswordReset

Sends a password reset email to the specified address.
string
required
The email address to send the reset link to.
Returns — Promise<void>

resetPassword

Completes a password reset using a token from the reset email. This revokes every session for that user and removes every push binding they hold, on every device — a reset is the remedy for a suspected compromise, so nothing is spared and there is no field to spare one with. The user signs in again everywhere, and each device re-binds for push on its own once it is next opened. Projects without the push bundle skip the binding step and are otherwise unaffected. Contrast Change Password, which a user calls with their own access token: it keeps their current session and can keep one device’s binding.
string
required
The reset token from the password reset email link.
string
required
The new password to set for the account.
Returns — Promise<void>

verifyEmail

Marks a user’s email address as verified using a code from the verification email.
string
required
The email verification code.
string
The verificationId returned with a sign-up code (by signUp, or in the body of a sign-in refused with auth/email-not-verified). Required to confirm such a code; leave it out for a code from sendVerificationEmail.
Returns — Promise<void>

sendVerificationEmail

Sends (or re-sends) an email-verification message to a user. Verification can be delivered as a short code or as a clickable link.
mode defaults to "code". In code mode tokenFormat is required and decides what else applies — tokenLength only with a short format, never with "hex" — enforced by TypeScript as a discriminated union, not just documented:
string
required
The user the service key acts as, who receives the verification email.
"code" | "link"
"code" (the default) emails a short token the user enters; "link" emails a verification URL.
"hex" | "numeric" | "alpha" | "alphanumeric"
Format of the generated token.
  • Required in code mode — the server’s default is "hex", which produces a 64-character token no one would want to type, so the SDK makes you choose.
  • Optional when mode: "link" (defaults to "hex") — the token sits in a URL, never read by a human, so format doesn’t matter.
number
Length of the generated token (4–12).
  • Optional in code mode with a "numeric", "alpha" or "alphanumeric" token (defaults to 6).
  • Not allowed when tokenFormat is "hex" — hex ignores length and always produces a fixed 64-character token.
  • Optional when mode: "link" (defaults to 6).
string | null
For mode: "link" only (TypeScript refuses it in code mode) — where to send the user after the link is verified; null for none.Must be an https address on one of your project’s Verified Domains (Dashboard → Settings → Domains). Each entry covers exactly the host it names, never its subdomains: example.com allows https://example.com/… on any port, but not www.example.com, which needs its own entry. A full address such as https://app.example.com covers only that host and port. localhost and *.localhost are always allowed, over http too. Anything else, including a custom-scheme deep link such as myapp://verified, is refused with 400 auth/redirect-url-not-allowed and no email is sent.
Returns — Promise<void>