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