File size: 1,683 Bytes
ceb943f
 
d5ba005
 
ceb943f
 
d5ba005
 
 
 
 
 
 
ceb943f
d5ba005
14b8081
ceb943f
 
 
 
 
 
 
 
14b8081
 
 
 
ceb943f
 
14b8081
ceb943f
14b8081
ceb943f
 
 
 
 
 
 
14b8081
 
eb36d07
14b8081
eb36d07
 
 
 
 
48e078d
 
ceb943f
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
import { betterAuth } from "better-auth";
import { drizzleAdapter } from "better-auth/adapters/drizzle";
import { drizzle } from 'drizzle-orm/postgres-js';
import postgres from 'postgres';
import * as schema from "./db/schema";

const pool = postgres(process.env.DIRECT_URL!, {
    ssl: 'require',
});
const authDb = drizzle(pool, {
    casing: 'snake_case',
});

export const auth = betterAuth({
    database: drizzleAdapter(authDb, {
        provider: "pg",
        schema: {
            user: schema.users,
            session: schema.sessions,
            account: schema.accounts,
            verification: schema.verifications,
        },
    }),
    account: {
        accountLinking: {
            enabled: true,
            trustedProviders: ["google"],
        },
        encryptOAuthTokens: false,
    },
    // Transitioning to Google-only authentication
    emailAndPassword: {
        enabled: false,
    },
    socialProviders: {
        google: {
            clientId: process.env.GOOGLE_CLIENT_ID || "",
            clientSecret: process.env.GOOGLE_CLIENT_SECRET || "",
            scope: ["https://www.googleapis.com/auth/youtube.readonly"],
        }
    },
    advanced: {
        useSecureCookies: process.env.NODE_ENV === "production", // Secure in prod, insecure in dev
    },
    trustedOrigins: [
        "http://localhost:3000",
        "http://127.0.0.1:3000",
        ...(process.env.BETTER_AUTH_URL ? [process.env.BETTER_AUTH_URL] : [])
    ],
    secret: process.env.BETTER_AUTH_SECRET || (process.env.CI ? "dummy_secret_for_ci_build" : undefined),
    baseURL: process.env.BETTER_AUTH_URL || (process.env.CI ? "http://localhost:3000" : undefined),
});