Built-in Auth
Sublay manages the full user lifecycle: sign-up, sign-in, and password reset using email and password. No external auth system needed.
OAuth
Sign in with Google, GitHub, Apple, or Facebook. Supports linking multiple providers to one account.
External Auth
Your backend signs a JWT. Sublay verifies it and creates or matches a user automatically. Keep your existing auth stack.
Token Model
All three auth modes produce the same token pair: an access token and a refresh token.
Refresh token rotation is enforced. Every time a refresh token is used, it is revoked and a new one is issued in its place. If the same refresh token is used twice (token reuse detected), the entire token family is revoked, signing out all sessions that shared it.
A 30-second grace period allows two requests that race to refresh the same token (e.g., two browser tabs loading simultaneously) to both succeed. The first request rotates the token; a second request arriving within that window receives the successor token instead of a reuse error.
Built-in Auth
Sublay provides a complete email/password authentication system out of the box. Use it when you do not have an existing user identity system and want Sublay to manage everything. What it includes:- User sign-up with email and password
- Sign-in returning an access token + refresh token + user object
- Sign-out (revokes the refresh token)
- Password change (requires current password)
- Password reset via email link (requires an email provider configured in the dashboard)
External Auth
Use this model when your application already has its own user management system (Supabase Auth, Auth0, Firebase Auth, NextAuth, a custom system, or anything else) and you want Sublay to associate its data with those users — without rebuilding auth.How It Works
1
Generate a JWT key pair in the dashboard
Sublay generates an RSA key pair (RS256) for your project. The public key is stored in Sublay. The private key is shown to you once — store it securely as a server-side environment variable. If it is lost or compromised, generate a new key pair from the dashboard.
2
Sign a JWT on your server when a user logs in
When your application detects a logged-in user, make a request to your own backend. Your backend signs a JWT with your private key and returns it to the client.The JWT payload must include:
The
userData object can include:The signed JWT is safe to pass to the client — it cannot be tampered with because the signature covers the payload using your private key.
3
Pass the JWT to Sublay
Pass the signed JWT to
SublayProvider via the signedToken prop (SDK), or call the verify external user API endpoint directly.Sublay verifies the JWT against the project’s stored public key. If valid, it looks up the user by the sub claim. If the user does not exist, it is created from the userData fields. If the user already exists, their profile fields are updated if anything has changed.On success, Sublay returns its own access token + refresh token pair tied to this user.Profile Sync
Every time a valid external JWT is presented, Sublay compares theuserData fields against the stored user record and updates any fields that have changed. Your user profiles in Sublay stay in sync with your external system automatically — no separate update call needed.
Security
The private key must never leave your server. Signing happens server-side; the client only receives the finished JWT. Because Sublay verifies using your public key, a client cannot forge or modify user data. See SDK Reference → Authentication → External for implementation guidance.OAuth
OAuth allows users to sign in using a third-party provider. Sublay handles the full flow: PKCE generation, state management, callback processing, and user creation or linking. Supported providers: Google, GitHub, Apple, FacebookSetup
Each provider must be configured in the project dashboard with:- The provider’s client ID and client secret
- A list of allowed redirect URIs (the URLs Sublay may redirect back to after authentication)
Flow Overview
1
Request an authorization URL
Call the authorize endpoint with the provider name and the
redirectAfterAuth URL. Sublay creates a short-lived state record (10-minute TTL) and returns an authorization URL pointing to the provider. For Google, a PKCE code verifier and challenge are generated automatically.2
Redirect the user to the provider
Redirect the user to the authorization URL. They authenticate with the provider and are sent back to Sublay’s callback endpoint.
3
Sublay processes the callback
Sublay exchanges the authorization code for the provider’s tokens, fetches the user profile, and resolves which Sublay user to return using this priority:
- Existing identity — if this provider account has signed in before, the matching user is returned immediately.
- Email match — if the provider’s email matches an existing user:
- The provider has verified the email: the new identity is linked to that account. If the account had never verified its own email, its password is removed, every other provider linked to it is unlinked, and all of its sessions are signed out (an access token already issued stops working within 30 minutes and can’t be used to add a password, a provider or a push device), since whoever set it up may not own the address (someone can sign up with another person’s email first). The provider sign-in keeps the account, and the email is marked verified. The user can add a password again with Set Password while signed in.
- The provider hasn’t verified the email: the sign-in is refused with
error=email_not_verified, because an unverified email can’t prove the account is theirs.
- New user — if no user has the email, a new user is created from the provider profile (name, email, avatar).
redirectAfterAuth URL with Sublay tokens appended as query parameters.4
Complete sign-in in your app
Your app reads the tokens from the redirect URL, stores them, and the user is signed in.
Account Linking
A user can link multiple OAuth providers (and a password account) to a single Sublay user record. To link an additional provider, the user must be signed in, and the OAuth flow is initiated via the link endpoint rather than the authorize endpoint. The new identity is attached to the existing account. This enables scenarios like “sign in with Google on a laptop and GitHub on another device” — both map to the same user. See SDK Reference → Authentication → OAuth for the full integration guide.Multi-Account Support
The SDK supports multiple simultaneously signed-in accounts in a single app instance. This is separate from account linking — it means multiple distinct user sessions can be held at once, with the ability to switch between them. Use cases: apps where a person manages multiple accounts, shared devices, or testing flows. See SDK Reference → Authentication → Multi-Account for the full guide.Authorization
Beyond authentication, Sublay enforces authorization on every request:- Most write operations require an authenticated user (or a service API key)
- Ownership checks are enforced server-side — a user cannot modify another user’s content through the normal API
- Space roles (owner, admin, moderator, member) control what is permitted within a space
- Service API keys act either as a user they name (
actingUserId), with exactly that user’s permissions, or as your app, which owns the records created without a user (see Acting as a user). They are intended for server-side use only — see Integration Options
Acting as a user
A request always acts as one user, or as the project itself:- A user token always acts as its own user. It never names an acting user: a request with a user token, or with no credentials, that sends
actingUserIdis refused with400 <resource>/acting-user-not-allowed, even when it names the token’s own user (an endpoint that requires sign-in may answer a request with no credentials with401first). The exception is the endpoints that always act as the app (below), which refuseactingUserIdfrom every caller with400 <resource>/unsupported-param. - A service key has no user of its own. To act as a user, it names that user in
actingUserId: in the query string on a GET or DELETE, in the body on a POST, PATCH or PUT (see Where each input goes). The named user must exist in the project: on every endpoint that acceptsactingUserId, an id that isn’t a user in this project is refused with404 <resource>/user-not-foundbefore the request runs. Acting as a user is total: the request gets exactly what that user’s own token would get, under that user’s own permissions, visibility, blocks and suspension. What a key may do depends on the endpoint:- Must name a user. Endpoints that only make sense for a person — commenting, reacting, following, RSVPing, creating a space or an event, deleting a space, every workspace action except reading a single workspace (creating, editing, deleting or transferring one, its invitations, its members), sending a reputation grant, reading a notification feed, matching people, updating a user’s profile — answer
400 <resource>/missing-user-idwithout it (A service key must send actingUserId: the user this request acts as.). To update a profile, the key must name the user in the path (403 user/unauthorizedotherwise), and the request then behaves exactly as that user’s own token. - May name a user (open reads). Reads shaped by who is looking return exactly what that user’s own token would get when the key names them, and exactly the anonymous view when it names nobody: entities (single, by foreign ID, by short ID, lists) and their reactions, comments (single, by foreign ID, threads) and their reactions, events, event lists and RSVP lists, spaces (single, by slug, by short ID, lists) and their member and team lists, rules and breadcrumb, a single workspace, user profiles and suggestions, follower, following and connection lists and their counts, a user’s comment history, user search, content search and Ask. A key naming nobody sees no drafts, no comment moderation details, only public events, and gets
403on a members-only space’s member list and404on a workspace, as an anonymous caller would; a private space, and every space under it, answers it404. Listing reputation grants needs credentials, so there a key naming nobody gets what a signed-in user in no conversation gets. - The owner acts. Editing, deleting or publishing an entity, editing or deleting a comment, and deleting a file act as the record’s owner. When the record has an author, the key must name them in
actingUserId(400 <resource>/missing-user-idwithout it) and the request runs exactly as their own; naming anyone else gets what that user’s token gets (403). A record with no author belongs to the app: only a key naming nobody may change it, and a user token is refused. A draft always has an author: one without an author is answered as not found (404), for every caller. - May create as the app. Creating an entity or uploading a file without
actingUserIdmakes an app-owned record with no author; with it, the record is that user’s, created under their own checks. A service key may always create an entity without an author. Other callers create one only as the project’s Who can create entities without an author setting allows (a request with no credentials through Create Entity, and any client throughcreateIfNotFound): Everyone (the default), Signed-in users only or No one from the client, set in the dashboard under Settings → General → SDK; a refused caller gets403 entity/authorless-creation-not-allowed. A draft always has an owner: creating one needs a user token or a key withactingUserId(400 entity/draft-requires-user). Creating a user by foreign id is for your backend only: Fetch or Create User by Foreign ID takes a service key, always creates as the app, and readsactingUserIdonly to shape the user it returns. Backdating (createdAt/updatedAton entity and comment create) is a service key ability, also when it acts as a user; a user token can’t set them. A date more than five minutes in the future is refused with400 <resource>/invalid-body(createdAt can't be in the future.). - Always acts as the app. Deleting a user, sending push notifications, minting reputation, incrementing an entity’s view count, and creating or dropping custom tables and columns take no acting user:
actingUserIdis refused with400 <resource>/unsupported-param, whoever sends it. Custom-table row endpoints are not in this list: thereactingUserIdcan be a column name. - Doesn’t use it. Endpoints where no user’s view matters — checking a username, link metadata, a file’s info — ignore
actingUserId, like any other field they don’t use. - Can’t be used. Where the person must prove it’s them — changing or setting a password, self-service account deletion, linking or listing OAuth identities, registering or removing a push device — the user’s own access token is required, and a key is refused with
403 <resource>/user-token-required. To delete an account from your server, use Delete User.
- Must name a user. Endpoints that only make sense for a person — commenting, reacting, following, RSVPing, creating a space or an event, deleting a space, every workspace action except reading a single workspace (creating, editing, deleting or transferring one, its invitations, its members), sending a reputation grant, reading a notification feed, matching people, updating a user’s profile — answer
userIdnever names the acting user. It only names a user the request is about: a target (the user to follow, block, invite or add to a conversation, or:userIdin a path) or a filter (the author filter onGET /entities). Don’t send the acting user asuserId: most endpoints that take an acting user refuse auserIdfield with400 <resource>/unsupported-param(workspace endpoints with400 workspace/invalid-bodyorworkspace/invalid-query), and each endpoint’s page lists the error. A service key is told to sendactingUserIdinstead; a user token, or a request with no credentials, is told that its token already acts as its user.
Where each input goes
Every endpoint reads each field from exactly one place, and the HTTP method decides which:- The path holds the resource the request acts on, and its parents:
DELETE /entities/:entityId,DELETE /events/:eventId/hosts/:userId.projectIdis read only from the path (/v8/:projectId/...). - GET and DELETE take every other field in the query string,
actingUserIdincluded. They take no body. - POST, PATCH and PUT take every other field in the body (JSON, or form fields on a
multipart/form-dataupload),actingUserIdand response options such asincludeandspaceReputationIdincluded. Nothing goes in their query string.
400 that names the right one, rather than ignored:
<area> is the endpoint’s own code prefix, for example entity, space or chat. A route v8 moved answers its old form with 400 <area>/unsupported-route, whose error names the route to call instead.
Saying “no value”
“Nothing” is said one way for filters and one way for values you set:- Filters choose which records come back. A filter that can match “has none” takes the word
none. A filter left out, or sent empty (spaceId=), takes its default, which is no filtering except where the table below says otherwise. The tree filters on lists (parentSpaceId,parentWorkspaceId) also take the wordany, meaning every level. Filters are usually in the query string; on the few reads that arePOSTs (such as search) they’re in the body, where leaving one out means no filter.nullandundefinedare never spellings of “none” in a URL. - Values you set on a create or update use JSON
nullfor “nothing”: no parent, the general bucket, remove the avatar. Leaving the field out means “don’t set it” on create and “leave it unchanged” on update. The string"none"is ordinary text there, except in the id fields listed below, where it is refused.
none:
These filters also take
any:
Other id filters, such as
spaceId on search and on moderated reports, take ids only.
On those filters, null or undefined in the query string (exact, case-sensitive) is refused with 400 <area>/unsupported-param, naming what to send instead:
relation and sortDir on GET /workspaces and GET /workspaces/mutual/:userId take neither word, but refuse null and undefined the same way, with 400 workspace/unsupported-param naming their values. Leave them out, or send them empty, for their defaults (reachable and desc).
These body id fields take JSON null, and refuse the string "none" with 400 <area>/unsupported-param naming null:
POST routes spaceReputationId goes in the body, where none is a value (the space-less bucket), not a “no value” spelling.
The SDKs follow the same rule: a filter set to null or undefined isn’t set, so it’s left out of the request, and "none" is sent only when you pass it.
