Skip to main content
The anonymousAuth plugin creates a lightweight guest identity on demand. The guest gets a real session and can use your app fully. When they decide to register, their data migrates to the new account without any loss.

Setup

lib/kavach.ts

Create guest

POST /auth/anonymous Creates a new anonymous user and returns a session. No request body needed.
Create guest (client)
The response shape is the same as any other sign-in. user.isAnonymous is true and the email and name fields are null.

Upgrade to real account

POST /auth/anonymous/upgrade Requires an active anonymous session. Converts the guest to a permanent user. The session stays active, the user ID does not change.
Upgrade guest (client)
After upgrade, user.isAnonymous becomes false and the account is treated the same as one registered normally. If emailPassword is also active, the email-verification flow applies. Error codes

Guest cleanup

Expired anonymous accounts can accumulate. Schedule regular cleanup with the built-in helper:
Scheduled cleanup
Deleting anonymous users is permanent. Any app data tied to their user ID will become orphaned unless you cascade deletes in your schema or handle cleanup in the onBeforeDelete hook.

Configuration reference

number
default:"604800 (7 days)"
How long an anonymous session lasts before expiring, in seconds.
boolean
default:"true"
Whether guests can convert to real accounts via the upgrade endpoint.
Last modified on April 29, 2026