fix: use Prisma adapter for Better Auth to resolve database adapter error
This commit is contained in:
parent
239f0e1227
commit
992a7fe72b
1 changed files with 6 additions and 51 deletions
|
|
@ -1,63 +1,18 @@
|
||||||
import { betterAuth } from 'better-auth';
|
import { betterAuth } from 'better-auth';
|
||||||
|
import { prismaAdapter } from 'better-auth/adapters/prisma';
|
||||||
|
import { db } from './db';
|
||||||
|
|
||||||
export const auth = betterAuth({
|
export const auth = betterAuth({
|
||||||
database: {
|
database: prismaAdapter(db, {
|
||||||
provider: 'postgresql',
|
provider: 'postgresql',
|
||||||
url: process.env.DATABASE_URL!,
|
}),
|
||||||
},
|
|
||||||
emailAndPassword: {
|
emailAndPassword: {
|
||||||
enabled: true,
|
enabled: true,
|
||||||
requireEmailVerification: false, // Can be enabled later
|
requireEmailVerification: false,
|
||||||
},
|
},
|
||||||
session: {
|
session: {
|
||||||
expiresIn: 60 * 60 * 24 * 7, // 7 days
|
expiresIn: 60 * 60 * 24 * 7, // 7 days
|
||||||
updateAge: 60 * 60 * 24, // Update session every 24 hours
|
updateAge: 60 * 60 * 24,
|
||||||
},
|
|
||||||
// Custom schema mapping for our auth_user table structure
|
|
||||||
schema: {
|
|
||||||
user: {
|
|
||||||
tableName: 'auth_user',
|
|
||||||
fields: {
|
|
||||||
id: 'id',
|
|
||||||
email: 'email',
|
|
||||||
emailVerified: 'email_verified',
|
|
||||||
name: 'name',
|
|
||||||
image: 'image',
|
|
||||||
createdAt: 'created_at',
|
|
||||||
updatedAt: 'updated_at',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
session: {
|
|
||||||
tableName: 'auth_session',
|
|
||||||
fields: {
|
|
||||||
id: 'id',
|
|
||||||
userId: 'user_id',
|
|
||||||
token: 'token',
|
|
||||||
expiresAt: 'expires_at',
|
|
||||||
ipAddress: 'ip_address',
|
|
||||||
userAgent: 'user_agent',
|
|
||||||
createdAt: 'created_at',
|
|
||||||
updatedAt: 'updated_at',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
account: {
|
|
||||||
tableName: 'auth_account',
|
|
||||||
fields: {
|
|
||||||
id: 'id',
|
|
||||||
userId: 'user_id',
|
|
||||||
accountId: 'account_id',
|
|
||||||
providerId: 'provider_id',
|
|
||||||
accessToken: 'access_token',
|
|
||||||
refreshToken: 'refresh_token',
|
|
||||||
idToken: 'id_token',
|
|
||||||
accessTokenExpiresAt: 'access_token_expires_at',
|
|
||||||
refreshTokenExpiresAt: 'refresh_token_expires_at',
|
|
||||||
scope: 'scope',
|
|
||||||
password: 'password',
|
|
||||||
createdAt: 'created_at',
|
|
||||||
updatedAt: 'updated_at',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue