Skip to main content
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.

Installation

1

Add the plugin to your auth config

auth.ts
2

Migrate the database

3

Add the client plugin

auth-client.ts

Usage

Sign in anonymously

This creates a real user record in the database with a generated email address (e.g. temp@<id>.com). The user gets a full session and can interact with your application normally. 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 the onLinkAccount callback to migrate any data:
auth.ts
Then sign in or sign up from the client as normal:
After account linking, the anonymous user record is deleted by default.

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 the user table: Use this field to adjust your application’s behavior for anonymous vs. authenticated users: