* Wip

* Add drizzle support

* Fix build

* fix migrations

* update dockerfiles

* update stuff

* simplify

* fix migrations

* remove migration code

* fix migrations

* update script

* wip

* bump script

* wip

* fix

* bump

* copy public

* wip

* wip
This commit is contained in:
Bill Yang 2025-03-05 12:29:30 -08:00 committed by GitHub
parent 8d6762d37d
commit 2b5c677933
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
29 changed files with 3583 additions and 206 deletions

View file

@ -2,6 +2,9 @@ import { betterAuth } from "better-auth";
import { username, admin, organization } from "better-auth/plugins";
import dotenv from "dotenv";
import pg from "pg";
import { drizzleAdapter } from "better-auth/adapters/drizzle";
import { db } from "../db/postgres/postgres.js";
import * as schema from "../db/postgres/schema.js";
dotenv.config();
@ -33,16 +36,26 @@ export let auth: AuthType | null = betterAuth({
},
});
export const initAuth = (allowList: string[]) => {
export function initAuth(allowedOrigins: string[]) {
auth = betterAuth({
basePath: "/auth",
database: new pg.Pool({
host: process.env.POSTGRES_HOST || "postgres",
port: parseInt(process.env.POSTGRES_PORT || "5432", 10),
database: process.env.POSTGRES_DB,
user: process.env.POSTGRES_USER,
password: process.env.POSTGRES_PASSWORD,
database: drizzleAdapter(db, {
provider: "pg",
schema: {
// Map our schema tables to what better-auth expects
user: schema.users,
account: schema.account,
session: schema.session,
verification: schema.verification,
organization: schema.organization,
member: schema.member,
},
}),
experimental: {
sessionCookie: {
domains: allowedOrigins,
},
},
emailAndPassword: {
enabled: true,
},
@ -50,7 +63,7 @@ export const initAuth = (allowList: string[]) => {
enabled: true,
},
plugins: [username(), admin(), organization()],
trustedOrigins: allowList,
trustedOrigins: allowedOrigins,
advanced: {
useSecureCookies: process.env.NODE_ENV === "production", // don't mark Secure in dev
defaultCookieAttributes: {
@ -59,4 +72,4 @@ export const initAuth = (allowList: string[]) => {
},
},
});
};
}