const authInstance = betterAuth({
secret: env.AUTH_SECRET,
baseURL: env.API_URL,
trustedOrigins: [env.CORS_ORIGIN || 'http://localhost:5173'],
database: drizzleAdapter(db, {
provider: 'pg',
schema: {
// auth
users,
sessions,
accounts,
verifications,
// authz
organizations,
members,
invitations,
},
usePlural: true,
}),
session: {
cookieCache: {
enabled: true,
maxAge: 5 * 60, // 5 minutes
version: "0.0.1",
strategy: 'compact',
},
},
advanced: {
useSecureCookies: env.APP_ENV !== 'local',
cookiePrefix:
env.APP_ENV === 'production' ? 'better-auth' : 'dev-better-auth',
crossSubDomainCookies: {
enabled: env.APP_ENV !== 'local',
domain: `.${new URL(env.CORS_ORIGIN).hostname}`,
},
database: {
generateId: false,
},
},
emailAndPassword: {
enabled: true,
},
socialProviders: {
google: {
clientId: env.AUTH_GOOGLE_ID,
clientSecret: env.AUTH_GOOGLE_SECRET,
prompt: 'select_account',
},
},
databaseHooks: {
user: {
create: {
after: async (user) => {
if (opts?.hooks?.onUserCreated) {
await opts.hooks.onUserCreated(user);
}
},
},
},
},
plugins: [organization()],
});
const authInstance = betterAuth({
secret: env.AUTH_SECRET,
baseURL: env.API_URL,
trustedOrigins: [env.CORS_ORIGIN || 'http://localhost:5173'],
database: drizzleAdapter(db, {
provider: 'pg',
schema: {
// auth
users,
sessions,
accounts,
verifications,
// authz
organizations,
members,
invitations,
},
usePlural: true,
}),
session: {
cookieCache: {
enabled: true,
maxAge: 5 * 60, // 5 minutes
version: "0.0.1",
strategy: 'compact',
},
},
advanced: {
useSecureCookies: env.APP_ENV !== 'local',
cookiePrefix:
env.APP_ENV === 'production' ? 'better-auth' : 'dev-better-auth',
crossSubDomainCookies: {
enabled: env.APP_ENV !== 'local',
domain: `.${new URL(env.CORS_ORIGIN).hostname}`,
},
database: {
generateId: false,
},
},
emailAndPassword: {
enabled: true,
},
socialProviders: {
google: {
clientId: env.AUTH_GOOGLE_ID,
clientSecret: env.AUTH_GOOGLE_SECRET,
prompt: 'select_account',
},
},
databaseHooks: {
user: {
create: {
after: async (user) => {
if (opts?.hooks?.onUserCreated) {
await opts.hooks.onUserCreated(user);
}
},
},
},
},
plugins: [organization()],
});