Sessions & Tokens
Session length and persistence, permission refresh, recent sign-in and step-up checks, sessions opened from your backend, and sessions a company ends.
Sessions are managed automatically by the SDK.
Step by step, with screenshots: session lifetime, trusted devices and signing a person out, and the Devices screen your users see.
| Behavior | Detail |
|---|---|
| Session duration | 30 days by default - configurable per session, capped at 180 days |
| Permission sync | hourly - role changes from the dashboard update automatically |
| Persistence | Store the session ID in a cookie or localStorage |
Session storage callbacks
Your SaaSOSProvider auth config takes three callbacks - nested under auth.callbacks - to persist the session. See the Installation page for the full provider setup.
// In your SaaSOSProvider auth config
auth={{
clientId: 'your-client-id',
redirectUrl: '/callback',
callbacks: {
getSession: async () => localStorage.getItem('sessionId'),
handleAuthentication: async (code) => {
const res = await fetch('/api/auth/token', {
method: 'POST',
body: JSON.stringify({ code }),
});
const data = await res.json();
return { sessionId: data.sessionId };
},
onSignOut: async () => localStorage.removeItem('sessionId'),
},
}}The three callbacks:
getSession- Return the stored session ID (from a cookie or your backend)handleAuthentication- Called after sign-in with the auth code. Exchange it for a session on your backend.onSignOut- Clear the stored session
Where to store the session ID
You choose how to persist the session ID. Each option has trade-offs:
| Approach | Security | Setup | Best for |
|---|---|---|---|
| HttpOnly cookie (recommended) | Immune to XSS - JavaScript cannot read it | Requires a backend route to set the cookie | SPAs with a Node.js backend |
| localStorage | Vulnerable to XSS - any script on the page can read it | One line - localStorage.setItem() | Quick prototypes, internal tools |
| Hybrid | HttpOnly cookie for session + localStorage for UI state | More complex | Production apps needing both security and client-side state |
Warning
If your app handles sensitive data (billing, PII), use HttpOnly cookies. localStorage is convenient for prototypes but exposes the session to cross-site scripting attacks.
Devices and active sessions
The SDK tracks the devices a user signs in from and the live sessions on each. Users can review their devices, rename them, and sign out individual sessions or entire devices.
Drop-in components - <Sessions /> lists live sessions with a revoke action; <Devices /> lists devices with rename, sign-out, and remove actions. Both are session-authed and need no config beyond SaaSOSProvider:
import { Devices, Sessions } from '@buildbase/sdk/react';
function SecurityPage() {
return (
<>
<Sessions />
<Devices />
</>
);
}Headless hooks - useSessions() and useDevices() return the same data plus actions for a custom UI:
import { useSessions } from '@buildbase/sdk/react';
function ActiveSessions() {
const { sessions, loading, revoke } = useSessions();
if (loading) return <p>Loading…</p>;
return (
<ul>
{sessions.map((s) => (
<li key={s.id}>
{s.device?.name ?? s.userAgent} — {s.ip}
{!s.current && <button onClick={() => revoke(s.id)}>Sign out</button>}
</li>
))}
</ul>
);
}Direct API access - useSessionsApi() and useDevicesApi() return memoized client instances:
| Client | Methods |
|---|---|
SessionsApi | list() → ISessionView[], revoke(id) |
DevicesApi | list() → IDeviceView[], rename(deviceId, name), signOut(deviceId), forget(deviceId) |
signOut(deviceId) revokes every live session on a device but keeps it in the list as signed out; forget(deviceId) also removes the device entirely. revoke(id) takes the session's public handle (ISessionView.id), not the raw session ID.
From SDK 1.0.0, each ISessionView also says how the session began, method: password, magic_link, email_code, phone_code, passkey, social, wallet, sso, guest, app_team (your team's session, the console's Sign in as user included), or unknown for a session opened before servers recorded it. issuedBy is { kind: 'app_team', appKeyName }, with the key's name, when your team opened the session as the user with an API key (below), and <Sessions /> marks it "Opened by the app's team". In the user's own list such a session has an empty ip and ipInfo: null: it was opened from your server, not their device. Both are absent from older servers.
To end the caller's own session use signOut() from useSaaSAuth(), and to end every session a user has use signOut({ everywhere: true }) - see sign in and sign out.
The built-in settings dialog includes security and devices screens - open them with openWorkspaceSettings('security') or openWorkspaceSettings('devices') from useSaaSAuth().
When a session last proved who it is
Every session records how it began and when its person last proved who they are: at the sign-in, or at a later re-confirmation (a person's own, or a company's). In your app, useSaaSAuth().session.authTime is that moment, ISO 8601, and session.amr lists the methods as RFC 8176 values, such as ['pwd', 'mfa']; two-step sign-in lists what a second step adds. Your backend reads them with the session in the x-session-id header:
curl -H "x-session-id: $SESSION_ID" "https://<your server>/api/v1/public/session"{
"signInMethod": "sso",
"authTime": "2026-10-17T09:12:44.000Z",
"amr": ["federated", "sso"],
"reverifiable": true
}| Field | What it holds |
|---|---|
signInMethod | How the session began, as method in the sessions list: password, magic_link, email_code, phone_code, passkey, social, wallet, sso, guest, app_team or unknown |
authTime | ISO 8601: the sign-in, or the latest confirmation. null for a session nobody signed in to, and for one opened before servers recorded it |
amr | How, as RFC 8176 values: pwd (password), email (magic link), webauthn (passkey, with mfa beside it when the device checked the person), federated (social sign-in), federated and sso (single sign-on) |
reverifiable | Whether this session can confirm it's you |
Only signing in moves authTime. The hourly permission refresh, staying active, and renewing the short-lived token the sign-in page holds never do. A confirmation moves authTime and amr but not when the session began, so a company's maximum session length still counts from the sign-in.
A session the server rebuilds from its stored copy after losing its cache keeps authTime and amr, and so how it was proved; a confirmation is not stored with it and is lost. Only a server running with SESSION_ID_ORG_SCOPED=true rebuilds sessions, and it is off by default: otherwise a session whose cached copy is lost ends, and the person signs in again.
Some sessions have nobody behind them who signed in, so authTime is null and reverifiable is false: a session from the token exchange, for the key's own user or as someone else, and a session an agent or connected app holds for the person. Such a session never counts as recent.
In your app (from SDK 1.0.0), useSaaSAuth().session carries the same four fields, read once the session loads and again after a confirmation, except that authTime is left out, not null, for a session nobody signed in to. A server from before this answers GET /session with a 404, and the fields are absent.
Confirming it's you
There is one Confirm it's you, with two kinds of change behind it, and both answer 403 reauth_required to a session that has not proved itself in the last 10 minutes.
- A person's own account: deleting the account, removing a connected account or a phone number, turning off text message codes. Any way the person signs in counts, with the second step when the change asks for it (
factors: ['mfa']). Confirm it's you covers these. - A company's settings: a company's security settings, under enterprise SSO, and removing a passkey while the person's company asks for passkeys. Only a strong proof counts, as this section says.
A confirmation of the second kind also counts for the first, within the same 10 minutes; the first never counts for the second. An older session is refused with a 403, never a 401, so the SDK does not take it for a dead session and sign the person out:
{
"error": true,
"success": false,
"code": "reauth_required",
"reason": "reauth_required",
"message": "Confirm it's you to change Globex's settings: sign in again at your company's identity provider.",
"maxAgeSeconds": 600,
"methods": ["sso"],
"reverifiable": true
}| Field | What it holds |
|---|---|
code | reauth_required. reason carries the same value |
message | The sentence to show, naming how to confirm |
maxAgeSeconds | The window: 600 |
methods | The ways that count for this person: sso (a fresh sign-in at their company's identity provider) and passkey (a passkey that checks it is them) |
reverifiable | false for a session that cannot confirm, whose message says so: "This session was not opened by you signing in, so it cannot confirm it's you. Sign in to the app yourself to make this change." |
What counts. A proof counts only for one of the ways in methods, within the 10 minutes. The sign-in itself counts when it proved one of them: a passkey that checked the person (amr with webauthn and mfa), or single sign-on that went through the identity provider asked to sign them in afresh. A password, a magic link, a social sign-in, a passkey that did not check the person, or an ordinary single sign-on never counts, however recent: the person confirms. A confirmation counts only for the way it used, so a passkey confirmation does not pass a company that asks for single sign-on.
The SDK's enterprise screens and Security screen (from SDK 1.0.0) handle it on their own: they show Confirm it's you, keep the change the person had not sent, and put it back on their return with "You confirmed it's you. Save again to apply it.", or, for an action such as removing a passkey or signing people out, "You confirmed it's you. Try it again to go ahead.", without sending it for them. In a screen of your own, catch it and send the person to confirm:
import { useState } from 'react';
import {
isReauthRequired,
useEnterpriseApi,
useSaaSAuth,
} from '@buildbase/sdk/react';
export function RequirePasskeysButton({
workspaceId,
}: {
workspaceId: string;
}) {
const api = useEnterpriseApi();
const { requireReverification } = useSaaSAuth();
const [notice, setNotice] = useState<string | null>(null);
async function requirePasskeys() {
try {
await api.savePolicy(workspaceId, {
signInMethods: { allowed: ['passkey'] },
});
} catch (error) {
if (!isReauthRequired(error)) throw error;
if (!error.reverifiable) return setNotice(error.message);
// Leaves for the sign-in page and comes back here. Press again then.
await requireReverification();
}
}
return (
<>
<button onClick={requirePasskeys}>Require passkeys</button>
{notice && <p role="alert">{notice}</p>}
</>
);
}isReauthRequired(error) is true for the 403 above, and the error carries maxAgeSeconds, methods and reverifiable. It is never a reason to sign out.
requireReverification
useSaaSAuth().requireReverification(options?) resolves 'recent' or 'redirecting'. 'redirecting' means the browser is on its way to the hosted sign-in page: do nothing more in that call. Before it leaves, the SDK makes a PKCE code verifier, keeps it in this tab, and sends only its S256 challenge. The person comes back to the page with reverified=1 and a one-time reverify_code on the URL; the provider takes both off without a reload and completes the confirmation with the code and the verifier. Only then is the session confirmed, and its authTime is the confirmation.
| Option | Default | What it does |
|---|---|---|
returnUrl | The page the person is on | Where to come back to. It must be on the origin of one of your auth client's redirect URLs |
maxAgeSeconds | none | Resolve 'recent' without leaving when the session proved who its person is within this many seconds. Without it, the person is always sent to confirm |
workspaceId | none | The workspace whose company's settings the person is changing: the confirmation is for that company (its ways, its activity), when they may manage it. Without it, for the person's own company |
methods | the server's | Offer only these of the ways that count, such as ['passkey'] for the Security screen's passkey removal, which only a passkey confirmation lets through |
factors | none | A person's own change only: ['mfa'] also asks for the second step. See Confirm it's you |
It throws reverify_unavailable for a session that cannot confirm: offer to sign out and in instead.
On the hosted page
The sign-in page opens as Confirm it's you, with the person's email fixed, and offers only the ways in methods, with Cancel back to returnUrl. It skips the trust-this-device and add-a-passkey screens. With single sign-on, the identity provider is asked to sign them in afresh; with a passkey, the passkey must check it is them. The same session comes back with a one-time code, and is recent once the browser that holds it completes the code: nobody is signed out, and your backend has no session code to exchange.
-
A company's sign-in methods. A passkey confirmation is not held to the person's company's list of sign-in methods, which says how its people sign in, not how they confirm it's them. The passkey sign-in answers a token that can finish only this confirmation, for this person, and never becomes a session.
-
No passkey yet. When a passkey is the only way that counts and the person has none on your sign-in domain, the page says so (
passkeySetup: trueon the page's intent) and offers their usual ways instead: their company's list, or every way your app offers. That sign-in answers a token that can only set up a first passkey; they add one their device verifies and confirm with it. -
Someone else. Signing in as another account is refused with
wrong_account, and the session keeps its old time. -
A way that does not count, such as a passkey that did not check the person, is refused with
reauth_method_not_allowed. -
An ended session. If the session ended while they were away, the confirmation is dropped with
session_endedand the page sends them back toreturnUrl, where your app finds its session gone and they sign in again. -
Every sign-in rule holds: a blocked account, and a company's IP allowlist and network, refuse a confirmation as they refuse a sign-in.
The API
A confirmation is bound to the browser that holds the session, as PKCE (RFC 7636) binds an authorization code: a code read off the return address is worthless anywhere else.
Start. POST /api/v1/public/session/reverify with the session in x-session-id and:
{
"returnUrl": "https://app.example.com/settings",
"codeChallenge": "E9Melhoa2OwvFrEMTJguCHaoeK1t8URWbuGJSstw-cM",
"workspaceId": "64f000000000000000000001",
"methods": ["passkey"]
}| Field | What it holds |
|---|---|
returnUrl | Required. Where the page comes back to, on the origin of one of the auth client's redirect URLs |
codeChallenge | Required for a company's confirmation. The S256 of a code verifier you keep in the browser: base64url, 43 to 128 characters. A start with no codeChallenge, workspaceId or methods is a person's own (Confirm it's you), which never counts for a company's settings |
workspaceId | Optional. The confirmation is for the company bound to this workspace, when the person may manage it: its ways count, and its activity records it. Otherwise it is for the person's own company |
methods | Optional. sso, passkey or both: only these of the ways that count are offered |
It answers { "success": true, "url": "..." }: the hosted page, bound to this session. Send the browser to url. The ways it offers are worked out by the server, from the person and the company, and methods can only narrow them.
Complete. The page comes back to returnUrl with reverified=1&reverify_code=<code>. From the same browser, POST /api/v1/public/session/reverify/complete with the session in x-session-id and { "code": "<reverify_code>", "codeVerifier": "<the verifier>" } answers { "success": true }, and the session is confirmed. The code lives 5 minutes and is spent by any attempt, a refused one included.
| Refusal | When |
|---|---|
400 invalid_request | At the start, codeChallenge is missing or not an S256 challenge: "This app's request to confirm it's you is incomplete. Reload the page and try again." |
400 invalid_return_url | At the start, returnUrl is not on the origin of one of the auth client's redirect URLs |
400 reverify_unavailable | At the start, nobody can confirm this session, or methods leaves none of the ways that count: "This session can't confirm it's you. Sign out and sign in again." |
400 invalid_reverify_code | At the completion, the code is unknown, used, expired or another session's, or the verifier does not match: "That confirmation has expired or was already used. Confirm it's you again." |
From your own server. A call your server makes with a person's session (withSession) gets the same 403. Send the person to confirm in their browser, then make the call again within the 10 minutes.
Older versions. An app on an SDK from before this shows the server's message where it shows any refusal, and cannot confirm: its start sends no code challenge and is refused with invalid_request. Signing out and in helps only when the new sign-in is with a passkey that checks the person, so update the SDK. A new SDK on an older server never sees reauth_required, and treats a 404 from /session/reverify as reverify_unavailable.
Opening a session as one of your users
Your backend can get a session for one of your users with an org API key, for a background job or for your support tooling. The session works on every /api/v1/public route, as withSession(sessionId) uses it.
curl -X POST "https://<your server>/api/v1/public/token/exchange" \
-H "Content-Type: application/json" \
-d '{"token":"<org id>:<key secret>","userId":"<user id>","expiresIn":3600,"reason":"Ticket 4812: the invoice page shows the wrong plan"}'It answers { sessionId, expiresIn, userId, orgId }.
| Field | What it does |
|---|---|
token | Required. An org API token, orgId:secret, from Settings > API keys |
userId | Whom the session is for. Only an owner or admin key may name a user other than its own; a narrower key opens a session for its own user only. Omitted, the key's own user |
workspaceId | Optional. The user must be a member of this workspace |
expiresIn | Optional. Seconds, from 60 to 30 days, 30 days by default |
reason | Optional, up to 200 characters. Why your team is opening it: the user's company reads it |
For one of a company's people, it is on their record. An exchange that names one of an enterprise's people, other than the key's own user, is always written to that company's trail as "Session opened by the app's team", and sends the enterprise.app_team_session webhook. The company sees "the app's team" and the key's name, never who on your team made the key, so name keys for what they do, such as "Support tool", and expect customers to read the name. Send a reason: the company reads it on the session's entry in its activity ("Support tool: Ticket 4812"), its CSV, the company API and its log streams, and a ticket number there answers the question its security team would otherwise send you. The company can also refuse these sessions in its access policy, which ends the ones already open too (your team signing in as the company's people).
Reuse the session. A session lasts up to 30 days. Exchange once and keep the session for its life rather than minting one per request: each exchange for a company's person is its own entry in the company's trail, never merged with the last.
The session is in the user's own sessions list with method: 'app_team', in the company's list of that person's sessions, and on the user's page in your console with the key's name. It never counts toward the user's session limit, so it cannot sign them out of their own devices. What is done with it in one of the company's workspaces is recorded as the person's act by the app's team, with the key's name. Nobody signed in to it, so it never counts as recent and cannot confirm it's you: a change that asks for that is refused with 403 reauth_required and reverifiable: false.
A refusal is { success: false, code, message }, with its own status:
| Status | code | Why |
|---|---|---|
| 401 | invalid_token | The key is malformed, unknown or inactive, or its creator is gone or blocked |
| 401 | token_expired | The key is past its expiry |
| 400 | invalid_user_id | userId is not a valid id |
| 403 | impersonation_not_allowed | The key is not an owner or admin key, and userId names someone other than its own user |
| 404 | user_not_found | No user with that userId in the org |
| 403 | user_blocked | The user userId names is blocked: "That user is blocked." |
| 400 | invalid_workspace_id | workspaceId is not a valid id |
| 403 | not_a_member | The user is not a member of workspaceId |
| 403 | app_team_sessions_refused | The user's company does not let your team sign in as its people. Nothing was minted, and the attempt is in the company's trail. The message names the company: "Globex does not let your team sign in as its people. Its admins can change this in their access policy." It is also the answer when workspaceId names a workspace of the company that refuses your team's sessions: "Globex does not let your team sign in as its people in Globex finance." |
| 403 | tenant_restricted | Your server passed on a company network's allowed-company-ids header, and the user is not one of the named companies' people |
| 400 | tenant_header_invalid | Your server passed on a company network's allowed-company-ids header on more than one line, and a line names one of your companies: "This network sent the allowed-company-ids header twice. Ask your IT team to make their proxy replace the header rather than add a copy." Nothing was minted |
When a company ends a session
A company's access policy can end its people's sessions: after a time without activity, after a maximum length, by signing a person or everyone out, or by ending one session on one device. The next request on such a session is answered 401 with the reason, rather than a bare 401:
{
"error": true,
"code": "session_ended",
"reason": "enterprise_max_age",
"minutes": 480,
"message": "Your company signs you out after 8 hours. Sign in again."
}reason | When | message |
|---|---|---|
enterprise_idle | No request for longer than the company's idle limit; minutes is the limit | "Your company signs you out after 30 minutes without activity. Sign in again." |
enterprise_max_age | Past the company's maximum session length; minutes is the length | "Your company signs you out after 8 hours. Sign in again." |
enterprise_signout | The company signed the person, or everyone, out | "Your company signed you out. Sign in again." |
enterprise_session_ended | The company ended this one session | "Your company ended this session. Sign in again." |
The lengths are the company's. Without one, the first two say "after a time without activity" and "after a set time". It is still a 401: the session is gone, and the SDK signs the person out as for any 401. The same answer comes back for seven days. A session that ended any other way (the person signed out or revoked it, was blocked, or changed their password) gets the bare 401, so nobody who signed themselves out is told their company did it. A server from before this sends a bare 401 every time.
In your app (from SDK 1.0.0), every API client reports it before its own sign-out handler runs, so that handler can say why. Like an access refusal, the SDK shows nothing on its own: say it on your sign-in screen or in your own chrome.
import { useSessionEnded } from '@buildbase/sdk/react';
export function SignedOutNotice() {
const { ended, dismiss } = useSessionEnded();
if (!ended) return null;
return (
<div role="status">
<p>{ended.message}</p>
<button onClick={dismiss}>Dismiss</button>
</div>
);
}useSessionEnded()returns{ ended, dismiss }.endedis{ reason, minutes?, message }untildismiss()clears it.auth.callbacks.onSessionEnded(ended)on the provider is called first, andonSessionExpired('expired')still follows, with its reasons unchanged, whichever of the SDK's clients made the request. Each is called once for a session, however many requests were on their way when it ended.- Outside React,
onSessionEnded(listener)andisSessionEnded(error)come from@buildbase/sdk. ended.messageis the server's sentence, in English.sessionEndedCopy(ended, locale)gives the translation key and the length in the reader's language, from the sentences the SDK ships in each of its locales.
On the hosted sign-in page, the next sign-in carries the reason along, and the page shows the same sentence as a note above the sign-in, not as an error. It only ever prints one of these four sentences, and a length only when it is one of the access policy's choices, so a link cannot make it say anything else.
When one workspace refuses a request
A company can hold one of its workspaces to stricter rules than its own policy: shorter sessions, fewer addresses, fewer ways in, single sign-on. A request there that does not meet them is a 403, never a 401: the session is kept, and the same session keeps working in the company's other workspaces.
{
"error": true,
"code": "workspace_access_refused",
"reason": "sso_required",
"workspaceId": "6710c0ffee0000000000f1a2",
"message": "Globex asks you to sign in with single sign-on to use Globex finance. Confirm it's you to continue.",
"reverifiable": true,
"methods": ["sso"]
}In your app (from SDK 1.0.0), useWorkspaceAccess(workspaceId) from @buildbase/sdk/react answers { refusal, confirm(), signInAgain(), dismiss() } for that workspace, and <WorkspaceAccessRefused /> shows the sentence with Confirm it's you or Sign in again. confirm() is requireReverification({ workspaceId, purpose: 'workspace' }): the hosted page says "Confirm it's you to continue in Globex finance", and the confirmation counts in that workspace. signInAgain() signs out and opens the sign-in page with "Your company asks you to sign in again to keep using one of its workspaces." useAccessRefused() leaves it out, so a refusal in one workspace is never read as one everywhere: the app's own banner stays quiet on a page showing a workspace that works. auth.callbacks.onAccessRefused still hears every refusal, with workspaceId.
The API. POST /api/v1/public/session/reverify takes purpose: "workspace" with workspaceId: the ways are the workspace's (single sign-on while it works, and a passkey the person holds when the rules allow one), and a person with neither gets reverify_unavailable and signs in again. While the workspace's rules cannot be read the start answers 503 policy_unavailable. A token exchange that names a workspace refusing your team's sessions is refused with app_team_sessions_refused, and the inbox leaves out a refused workspace's notifications until the person is back in.
How tokens are kept and told apart
This is how BuildBase keeps your users' tokens and keys, so that someone holding a copy of the database, a backup or a log line can do as little as possible with it. You don't need to set anything up.
Stored as digests, never as issued
A digest is a one-way fingerprint of a token, made with SHA-256. BuildBase can check a token someone presents against its digest, but nobody can turn the digest back into the token. So for these credentials, the database never holds the working value:
| Credential | What BuildBase stores | What that means |
|---|---|---|
| An OAuth 2.0 refresh token (what lets an app keep a person signed in), for one of your auth clients or an agent | Its SHA-256 digest | BuildBase finds the token by its digest every time it's refreshed, revoked or checked (introspection). A copy of the collection, or of a backup taken since, holds no refresh token that works |
| An org API key (Settings > API keys) | Its SHA-256 digest, and a masked preview for the console's list | The key is shown once, when it is made. Lose it and make another |
| A company API key | A hash | Shown once, when it is made |
| A session ID | Its SHA-256 key, in the session cache and the session mirror | Lookups go by the key. While the release that introduced keys rolls out, a new session is also stored as issued, beside its key. That way a server rolled back mid-deploy still finds it, and nobody is signed out. A later release stops that |
Refresh tokens from before hashing are revoked once. When hashing arrived, every stored refresh token was rewritten as its digest, so none sits in the collection as issued any more. But a backup taken before then still holds working tokens. So right after that release is deployed, the refresh tokens issued to your auth clients before hashing are revoked once, by hand. A person who held one signs in to your app one more time. Agent grants are left alone. So was every token issued after hashing, since none was ever stored in a form a copy could use.
Agent refresh tokens rotate. Each time an agent refreshes, it gets a new refresh token and the one it presented is retired. A retired token used again is treated as stolen, and ends the whole chain: every refresh token issued from that grant (the access the person gave the agent) stops working, and no new one can be issued from it. Your own auth clients keep one refresh token for the life of the grant.
Every token says what it is for
A token made for one job can't be used for another. A sign-in token one of your users holds is refused by your console, and a magic link opens nothing but the link's own endpoint.
BuildBase signs several kinds of token:
- the console's session
- the sign-in token your app's users get from the hosted page
- a magic link
- a device identity
- checkout return links
- the tokens behind link checks and email tracking
Each one carries a typ claim (a field inside the token) naming its kind, except, for now, the sign-in token your app's users get, which is told apart by its audience alone. A token that opens a session also carries an aud claim (its audience) naming the part of the platform it opens: your console, your app's sign-in, or the control plane (BuildBase's central service). Each entry point accepts only its own kind. A token made before these claims existed is still judged the way its entry point judged it before.
Sign-ins that leave the page are bound to the browser
Some sign-ins send the person to another site and back: a social provider (Google, LinkedIn, GitHub, Microsoft, Apple, Lovable, Vercel, or your custom OpenID Connect provider), Google One Tap, and Continue with SSO for enterprise single sign-on. Each one can only finish in the browser that started it.
That's done with PKCE (RFC 7636), a check that the sign-in finishes in the same browser that started it. Step by step:
- Before it leaves, the hosted sign-in page makes a random secret (the code verifier) and keeps it in that tab. It sends only a fingerprint of it (the S256 challenge) with the start.
- The start refuses a request with no challenge, before anything is stored. The social start and the enterprise SSO start take it as
challengein the query string. Google One Tap takes it in the request body. - When the provider sends the person back, no token goes into the address bar. The sign-in waits under a single-use handoff code. The page redeems it at
POST /api/v1/auth/login-handoffwith{ code, verifier }, and a verifier that doesn't match the challenge is refused.
So a handoff code read from an address bar, a log or a proxy is worthless on its own. It also stops login CSRF: an attacker starting a sign-in as themselves and getting one of your users' browsers to finish it, so the user ends up in the attacker's account.
If you build your own sign-in screen against these routes, make a verifier, send its challenge, and keep the verifier for the redeem. A sign-in that starts at the company's identity provider has no start to carry a challenge, so it keeps its own path (sign-in that starts at the identity provider).
Magic links follow the same idea, through a setting that's on unless you turn it off: a link signs a person in only in the browser that asked for it (require the same browser).
Common questions
Role changes not taking effect? Permissions refresh hourly. Sign out and back in for immediate effect.
Session lost on refresh? Make sure your getSession callback reads from persistent storage, not memory.
Asked to confirm it's you? A 403 reauth_required means the change needs a proof from the last 10 minutes, one of the ways in methods. It keeps the session: confirm with requireReverification() and try again (confirming it's you).
Session expired? Sessions last 30 days by default and can be configured to last up to 180 days. Trusted devices and the org session policy also affect expiry, and so does the access policy of an enterprise the person belongs to: its idle limit (15 minutes to 30 days) and its maximum session length (1 hour to 180 days) end a session sooner, with a 401 session_ended that says which (when a company ends a session). Its IP allowlist answers a 403 ip_not_allowed, and its network a 403 tenant_restricted, each of which keeps the session (see Access policy). When a session expires, the user must sign in again.
Next Steps
- Protected Routes - Guard routes based on auth state.
- Workspaces Overview - Multi-tenant workspaces.