{typescript}
import { betterAuth } from "better-auth";
import { nextCookies } from "better-auth/next-js";
import { drizzleAdapter } from "better-auth/adapters/drizzle";
import { db } from "../db";
import * as schema from '../db/schema';
if (!process.env.BETTER_AUTH_SECRET) {
throw new Error('BETTER_AUTH_SECRET environment variable is not set');
}
export const auth = betterAuth({
// Add secret for encryption and session handling
secret: process.env.BETTER_AUTH_SECRET,
// Database configuration
database: drizzleAdapter(db, {
provider: 'pg',
// Map model names to schema objects using lowercase to match schema definitions
schema: {
user: schema.user,
session: schema.session,
account: schema.account,
verification: schema.verification
}
}),
// Account configuration
account: {
modelName: "account",
accountLinking: {
enabled: true, // Enable account linking
trustedProviders: ["google"], // Consider Google a trusted provider
}
},
// OAuth providers
socialProviders: {
google: {
clientId: process.env.GOOGLE_CLIENT_ID as string,
clientSecret: process.env.GOOGLE_CLIENT_SECRET as string,
}
},
// OMMITTING EXTRA CODE DUE TO LIMIT
// Next.js integration
plugins: [nextCookies()]
});
{typescript}
import { betterAuth } from "better-auth";
import { nextCookies } from "better-auth/next-js";
import { drizzleAdapter } from "better-auth/adapters/drizzle";
import { db } from "../db";
import * as schema from '../db/schema';
if (!process.env.BETTER_AUTH_SECRET) {
throw new Error('BETTER_AUTH_SECRET environment variable is not set');
}
export const auth = betterAuth({
// Add secret for encryption and session handling
secret: process.env.BETTER_AUTH_SECRET,
// Database configuration
database: drizzleAdapter(db, {
provider: 'pg',
// Map model names to schema objects using lowercase to match schema definitions
schema: {
user: schema.user,
session: schema.session,
account: schema.account,
verification: schema.verification
}
}),
// Account configuration
account: {
modelName: "account",
accountLinking: {
enabled: true, // Enable account linking
trustedProviders: ["google"], // Consider Google a trusted provider
}
},
// OAuth providers
socialProviders: {
google: {
clientId: process.env.GOOGLE_CLIENT_ID as string,
clientSecret: process.env.GOOGLE_CLIENT_SECRET as string,
}
},
// OMMITTING EXTRA CODE DUE TO LIMIT
// Next.js integration
plugins: [nextCookies()]
});