lib/jwt.ts). On the web there is
also a per-environment SSO cookie shared by the apps (ADR 0014).
The tokens
Every sign-in method (password, provider, magic link) ends in the same
loginCommon and returns the
same payload. Session-bearing responses are sent with cache-control: no-store and
pragma: no-cache. In deep links the tokens travel in the fragment (#access_token=...), never in the
query.
Refresh with profile/me
GET /api/v3/auth/profile/me, with the JWT as bearer, returns a new JWT and the current payload,
including has_created_password. It keeps the gotrue_sid and answers token_ws: "": clients keep
their Supabase token. It answers 401 when the JWT is missing, invalid, expired or revoked: a token
revoked by logout or by a revocation marker can never be exchanged for a new one (D-02). Limit: 60 per
hour per user.
Pending (REQ-109, T-113). Today
profile/me issues a new token with a new expiry, so a chain of
refreshes can extend the session. The decision is that the new token never expires after the one
presented.Lifetime (TTL)
Tokens issued before the cap keep their one-year expiry. That is why revocation markers are kept for
400 days: they must outlive the longest token.
Signing out
POST /api/v3/auth/logout, with the JWT as bearer and no body, answers 200 { ok: true }. It is
idempotent: an already revoked session or a JWT without gotrue_sid also answers { ok: true }. It
answers 401 only when the bearer is missing or malformed.
When MaihueGO gets a 401
The app clears the local session only when the call carried the stored bearer and the body says the token was rejected («Invalid or expired token», «The token has been revoked», among others). It never does so on a403. It clears session, accounts, plans, profile, courtesy flags and the query
cache, shows the session-expired toast and goes back to /(auth)/auth. Several parallel 401s sign
out once (D-122, D-124).
Revocation per login
lib/auth/session/session-revocation.ts stores one marker per login (revokeSessionsBefore): any
token issued before that marker is rejected. When validating a token, the API checks it in Redis
together with the jti blacklist. It is used by:
- Changing the password with «Cerrar sesión en los demás dispositivos»: the device that made the
change receives a new JWT. The same change also ends the login’s other GoTrue sessions through the
auth_end_login_sessionsfunction (service role only), so a device that kept its Supabase refresh token cannot exchange it for a new Horizon JWT. - Apple
consent-revokedandaccount-deletenotifications: every session of the login is revoked. - A login deleted, soft-deleted or banned in Supabase Auth through any channel (Horizon, the Supabase
dashboard, SQL): a trigger on
auth.usersrecords the event and theauth/login-revocationcron writes the marker within about two minutes (D-01).
profile/me, permissions/me,
abandon-registration) run the same check, so a revoked token is refused there too (D-02).
Context and organization switch
context-switch limit: 30 per 10 minutes per user.
SSO between web apps
- Same site (*.bbrands.io)
- Another domain (bbx)
reauth=1 is sent only when the app rejected a cookie that is still valid (a client 401); a missing
or expired cookie does not carry it (D-223, D-228). Consumer app variables: APP_ENV,
AUTH_HMAC_SECRET (32 characters or more, same environment), AUTH_SESSION_COOKIE_DOMAIN and
NEXT_PUBLIC_ROUTE_API.
2FA gate
ADR 0134 requires password, provider and magic-link sign-ins to go through the 2FA gate beforenext
on the web. Today it is inert: the authenticate-two-factor-ui flag is false in every environment, the
auth/2fa/* pages answer 404 and there is no second-factor backend (it comes with the Better Auth
migration). Sign-in redirects to auth/2fa/verify only when the backend answers requires_2fa, which
does not happen today.
MaihueGO session store
The session store persistshasCreatedPassword. That value is no longer hardcoded to true: it is
refreshed from profile/me and decides whether Home shows the «Crea tu contraseña» alert and whether
Settings offers to create or change the password.