Background tasks configuration for serverless platforms
On serverless platforms like Vercel and Cloudflare Workers, configure `advanced.backgroundTasks` to defer non-critical work after the response is sent. Pass a handler like Vercel's `waitUntil` function. Use `ctx.context.runInBackground` or `ctx.context.runInBackgroundOrAwait` in hooks to defer tasks like cleanup, analytics, rate limit updates, and email sending.
Background tasks hook example with runInBackground
In a hook, use `ctx.context.runInBackground()` to defer non-critical work. Example: `ctx.context.runInBackground(logSignUp(ctx.context.newSession?.user.id))` defers logging after the sign-up response is sent.
SSR optimization with server-side session pre-fetch
For frameworks supporting server-side rendering, pre-fetch the user session on the server using `auth.api.getSession()` and pass it to the client as a fallback. Use `await headers()` to retrieve headers for the API call.
verify-email template variables
The verify-email template requires: verificationUrl, userEmail. Optional variables: verificationCode (for code-based verification), userName, appName, expirationMinutes.
reset-password template variables
The reset-password template requires: resetLink, userEmail. Optional variables: userName, appName, expirationMinutes.
change-email template variables
The change-email template requires: confirmationLink, newEmail, currentEmail. Optional variables: userName, appName, expirationMinutes.
sign-in-otp template variables
The sign-in-otp template requires: otpCode, userEmail. Optional variables: appName, expirationMinutes.
verify-email-otp template variables
The verify-email-otp template requires: otpCode, userEmail. Optional variables: appName, expirationMinutes.
reset-password-otp template variables
The reset-password-otp template requires: otpCode, userEmail. Optional variables: appName, expirationMinutes.
magic-link template variables
The magic-link template requires: magicLink, userEmail. Optional variables: appName, expirationMinutes.
two-factor template variables
The two-factor template requires: otpCode, userEmail. Optional variables: userName, appName, expirationMinutes.
application-invite template variables
The application-invite template requires: inviteLink, inviterName, inviterEmail, inviteeEmail. Optional variables: appName, expirationDays.
delete-account template variables
The delete-account template requires: deletionLink, userEmail. Optional variables: userName, appName, expirationMinutes.
stale-account-admin template variables
The stale-account-admin template requires: userEmail, userId, adminEmail, daysSinceLastActive, loginTime. Optional variables: userName, appName, loginLocation, loginDevice, loginIp.
Lynx magic link authentication
Sign in with magic link using plugin: await authClient.signIn.magicLink({ email: "test@email.com" }). Requires magicLinkClient() plugin to be enabled.
Anonymous account linking in mobile and in-app browsers
Linking an anonymous account after a social login now works in Expo and other in-app browsers, where the callback returns without the usual cookie. A new `addOAuthServerContext` API carries trusted data across the login that a client cannot forge. Most apps need no changes; if state was carried across OAuth redirect manually, move it onto `addOAuthServerContext`.