From dcaba6ffd8f2531769474fedc3929f3dcb2eaa6b Mon Sep 17 00:00:00 2001 From: Rin Arakaki Date: Fri, 9 May 2025 11:15:30 +0900 Subject: [PATCH] docs: add field mappings for migrating from next-auth v4 (#2315) * Update next-auth-migration-guide.mdx * Update next-auth-migration-guide.mdx * Update next-auth-migration-guide.mdx * Update next-auth-migration-guide.mdx * Update next-auth-migration-guide.mdx --- .../docs/guides/next-auth-migration-guide.mdx | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/docs/content/docs/guides/next-auth-migration-guide.mdx b/docs/content/docs/guides/next-auth-migration-guide.mdx index cebabd3834..4bab71a3ca 100644 --- a/docs/content/docs/guides/next-auth-migration-guide.mdx +++ b/docs/content/docs/guides/next-auth-migration-guide.mdx @@ -21,7 +21,9 @@ Instead of altering your existing database column names, you can map them to mat #### User Schema -Your existing user schema is likely compatible with Better Auth, so no changes are needed. +Map the following fields in the session schema: + +- (next-auth v4) `emailVerified`: datetime → boolean #### Session Schema @@ -29,6 +31,8 @@ Map the following fields in the session schema: - `expires` → `expiresAt` - `sessionToken` → `token` +- (next-auth v4) add `createdAt` with datetime type +- (next-auth v4) add `updatedAt` with datetime type ```typescript title="auth.ts" export const auth = betterAuth({ @@ -48,11 +52,15 @@ Make sure to have `createdAt` and `updatedAt` fields on your session schema. Map these fields in the account schema: +- (next-auth v4) `provider` → `providerId` - `providerAccountId` → `accountId` - `refresh_token` → `refreshToken` - `access_token` → `accessToken` -- `access_token_expires` → `accessTokenExpiresAt` +- (next-auth v3) `access_token_expires` → `accessTokenExpiresAt` and int → datetime +- (next-auth v4) `expires_at` → `accessTokenExpiresAt` and int → datetime - `id_token` → `idToken` +- (next-auth v4) add `createdAt` with datetime type +- (next-auth v4) add `updatedAt` with datetime type Remove the `session_state`, `type`, and `token_type` fields, as they are not required by Better Auth.