The Anonymous plugin lets users have a full authenticated experience without providing an email, password, or any other personally identifiable information. They can link an authentication method to their account at any point. This is useful for e-commerce flows where you want to preserve a shopping cart, or any application where you want to reduce friction for new visitors.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/better-auth/better-auth/llms.txt
Use this file to discover all available pages before exploring further.
Installation
Add the plugin to your auth config
auth.ts
Migrate the database
Add the client plugin
auth-client.ts
Usage
Sign in anonymously
temp@<id>.com). The user gets a full session and can interact with your application normally.
Link an account
When an anonymous user wants to create a permanent account, they can sign in or sign up with another method. Their anonymous session will automatically be linked to the new account. First, configure theonLinkAccount callback to migrate any data:
auth.ts
Delete an anonymous user
Anonymous users can also explicitly delete their own account:The
/delete-anonymous-user endpoint is automatically disabled if you set disableDeleteAnonymousUser: true.Options
emailDomainName
Customize the domain used in generated email addresses. Default format is temp@{id}.com.
generateRandomEmail
Provide a fully custom function to generate email addresses:
If
generateRandomEmail is provided, emailDomainName is ignored. You are responsible for uniqueness and valid email format.generateName
Generate a display name for anonymous users:
onLinkAccount
Callback fired when an anonymous user links their account to a permanent authentication method. Receives { anonymousUser, newUser }.
disableDeleteAnonymousUser
Set to true to prevent anonymous users from calling the /delete-anonymous-user endpoint. Also disables automatic deletion when an account is linked.
Schema
The anonymous plugin adds one field to theuser table:
| Field | Type | Description |
|---|---|---|
isAnonymous | boolean | true for anonymous users, null/false for regular users |