33 lines
962 B
TypeScript
33 lines
962 B
TypeScript
import { betterAuth } from 'better-auth';
|
|
import { drizzleAdapter } from 'better-auth/adapters/drizzle';
|
|
|
|
import { db } from './db/client';
|
|
import { schema } from './db/schema';
|
|
import { hashPassword, verifyPassword } from './utils/password';
|
|
|
|
const trustedOrigins = process.env.BETTER_AUTH_TRUSTED_ORIGINS
|
|
? process.env.BETTER_AUTH_TRUSTED_ORIGINS.split(',').map((origin) => origin.trim()).filter(Boolean)
|
|
: undefined;
|
|
|
|
export const auth = betterAuth({
|
|
database: drizzleAdapter(db, {
|
|
provider: 'pg',
|
|
schema: {
|
|
...schema,
|
|
user: schema.users,
|
|
},
|
|
}),
|
|
emailAndPassword: {
|
|
enabled: true,
|
|
password: {
|
|
hash: async (password) => hashPassword(password),
|
|
verify: async ({ hash, password }) => verifyPassword(password, hash),
|
|
},
|
|
},
|
|
secret: process.env.BETTER_AUTH_SECRET,
|
|
baseURL: process.env.BETTER_AUTH_URL,
|
|
trustedOrigins,
|
|
});
|
|
|
|
export type AuthSession = Awaited<ReturnType<typeof auth.api.getSession>>;
|