Skip to content

Anonymous Sign-In

Anonymous sign-in creates a real user in auth.users and issues a normal session JWT. The user gets a stable auth.uid() for the lifetime of the session, but has no email or password until they upgrade.

This is useful for guest checkout, try-before-sign-up flows, and saving progress before account creation.

Not the same as the anon API key

Anonymous sign-inAnon API key
What it issignInAnonymously() creates a user + JWTPublic key for unauthenticated API requests
Postgres roleauthenticated (user JWT)anon (no user JWT)
auth.uid()Real user IDNULL
JWT claimis_anonymous: trueNo user session

Use the anon key for public read access with Public access rules. Use anonymous sign-in when you need a per-visitor user ID and LoggedIn access rules without asking for credentials first.

Enable anonymous sign-in

Anonymous sign-in is disabled by default. Enable it on the auth server by adding this to the project’s .env (supatype.config.ts has no key for it):

Terminal window
SUPATYPE_EXTERNAL_ANONYMOUS_USERS_ENABLED=true

While it is off, signInAnonymously() is refused with 422 and the error code anonymous_provider_disabled. See Self-hosting configuration for the full auth variable reference.

Check whether it is enabled at runtime:

const res = await fetch(`${SUPATYPE_URL}/auth/v1/settings`)
const settings = await res.json()
console.log(settings.external?.anonymous_users) // true when enabled

Sign in anonymously

const { data, error } = await supatype.auth.signInAnonymously()
if (error) {
console.error("Anonymous sign-in failed:", error.message)
return
}
console.log("Guest user ID:", data.user?.id)
console.log("Is anonymous:", data.user?.isAnonymous) // true

Pass optional user metadata (stored in user_metadata):

const { data, error } = await supatype.auth.signInAnonymously({
options: {
data: {
display_name: "Guest",
},
},
})

If captcha is enabled on your project, pass the verification token:

await supatype.auth.signInAnonymously({
options: {
captchaToken: tokenFromCaptchaWidget,
},
})

The session is persisted by the client SDK like any other sign-in. If the user clears storage, signs out, or switches devices, the anonymous account cannot be recovered.

Upgrade to a permanent account

Link an email or phone to convert the anonymous user into a permanent account. The user ID stays the same, so related rows keep their foreign keys.

const { data, error } = await supatype.auth.updateUser({
email: "alice@example.com",
password: "strongpassword123",
})

When the auth server auto-confirms emails (local dev’s default), the email is attached straight away. Otherwise a confirmation email is sent, and the email is attached when the user follows the link. From then on user.isAnonymous is false. A password on its own is refused: an anonymous user needs an email or phone in the same update. See Email & Password for confirmation and password flows.

Access rules and RLS

Anonymous users satisfy LoggedIn: they have a valid JWT and a non-null auth.uid().

Keep anonymous users out

To restrict an action to registered users only, test the is_anonymous claim as well as the sign-in:

import type {
All, Claim, Eq, Int, Literal, LoggedIn, Model, RelatedTo, SupatypeAuthUser, UUID,
} from "@supatype/types"
type Registered = All<[LoggedIn, Eq<Claim<"is_anonymous">, Literal<"false">>]>
export type Order = Model<{
id: UUID
total: Int
buyer: RelatedTo<SupatypeAuthUser>
}, {
tableName: "orders"
access: {
read: LoggedIn
// Guests can read, only registered users create
create: Registered
}
}>

The auth server puts is_anonymous in every access token it issues, true for a guest and false for a real account, so Registered admits exactly the users who signed up or added an email or phone. A token without the claim, such as one minted by your own code, is denied.

Write the literal as the string "false": Claim<> reads the JWT by dotted path as text, and that form works on every engine version. Literal<false> means the same thing on engines after 0.9.0, which read the claim as a JSON boolean when it is compared with a boolean. Engine 0.9.0 and earlier refuse it at push with operator does not exist: text = boolean.

Keep anonymous users out of a bucket

The same rule works on a bucket, where it is applied to storage.objects:

import type { All, Bucket, Claim, Eq, Literal, LoggedIn } from "@supatype/types"
export type Uploads = Bucket<"uploads", {
accessMode: "private"
access: {
read: LoggedIn
// Guests can read, only registered users upload
create: All<[LoggedIn, Eq<Claim<"is_anonymous">, Literal<false>>]>
}
}>

BucketLoggedIn admits guests, like LoggedIn. To give each user their own folder as well, see one folder per user.

MFA-gating works the same way with the aal claim; see MFA.

Rate limits and cleanup

Anonymous sign-ins are rate-limited per IP (default 30 per hour, the auth server’s SUPATYPE_RATE_LIMIT_ANONYMOUS_USERS). Like every per-IP limit, it applies only when the auth server can read the caller’s IP from the header SUPATYPE_RATE_LIMIT_HEADER names, which the generated stack does not set. Anonymous users older than 30 days are deleted only when the auth server’s database cleanup is also on (SUPATYPE_DB_CLEANUP_ENABLED=true). It is off by default and the generated stack does not set it, so without it anonymous users stay until you remove them.

With cleanup on, the 30 days count from when the account was created, so a guest still using the app is deleted all the same. Rows whose user field declares onDelete: "cascade" are deleted with it, a "setNull" field is cleared, and a field without onDelete keeps an id that no longer matches a user. Prompt guests to add an email or phone before then: once they do, is_anonymous is false and the cleanup leaves them alone.

Consider enabling captcha (SUPATYPE_SECURITY_CAPTCHA_ENABLED) on production projects to reduce abuse.

Next steps