All files / src auth.config.ts

0% Statements 0/3
100% Branches 0/0
0% Functions 0/1
0% Lines 0/3

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53                                                                                                         
// better-auth
import { betterAuth, google, type Auth } from 'better-auth';
import { drizzleAdapter } from 'better-auth/adapters/drizzle';
// drizzle
import { type NodePgDatabase } from 'drizzle-orm/node-postgres';
import { type Pool } from 'pg';
 
export const betterAuthConfig = (
  db: NodePgDatabase<Record<string, never>> & { $client: Pool },
  schema: Record<string, any>,
  betterAuthSecret: string,
  betterAuthUrl: string,
  discordClientId: string,
  discordClientSecret: string,
  googleClientId: string,
  googleClientSecret: string
): Auth => {
  const auth = betterAuth({
    database: drizzleAdapter(db, {
      provider: 'pg', // or "mysql", "sqlite"
      schema,
    }),
    secret: betterAuthSecret,
    baseURL: betterAuthUrl,
    // allow requests from the frontend development server
    trustedOrigins: ['https://pay-crew2.yukiosada.work', 'http://localhost:5173'],
    socialProviders: {
      discord: {
        clientId: discordClientId,
        clientSecret: discordClientSecret,
        scope: ['identify', 'email'],
      },
      google: {
        clientId: googleClientId,
        clientSecret: googleClientSecret,
        scope: [
          'openid',
          'https://www.googleapis.com/auth/userinfo.profile',
          'https://www.googleapis.com/auth/userinfo.email',
        ],
      },
    },
    account: {
      accountLinking: {
        enabled: true,
        allowDifferentEmails: false,
      },
    },
  });
 
  return auth;
};