Installation
1
Add the server plugin
Import and configure
magicLink in your auth config. You must provide a sendMagicLink function that delivers the link to the user:auth.ts
2
Add the client plugin
Add
magicLinkClient to your auth client:auth-client.ts
Usage
Send a magic link
CallsignIn.magicLink on the client with the user’s email address:
sign-in.ts
If the email address is not registered and
disableSignUp is not true, the user is automatically signed up on first use.Verification flow
When the user clicks the link:- Better Auth validates the token.
- If valid, the user is authenticated and redirected to
callbackURL. - If invalid or expired, they are redirected to
callbackURL?error=...(orerrorCallbackURLif provided).
Manual verification
If you need to verify a token yourself (e.g. you built your own link format), call themagicLink.verify endpoint:
verify.ts
Server-side sendMagicLink callback
The function receives:
A
ctx context object is passed as the second argument.
auth.ts
Configuration options
Token expiry example
auth.ts