add new user (#18)

This commit is contained in:
Bill Yang 2025-02-19 21:00:55 -05:00 committed by GitHub
parent 8ada9b8c16
commit 61d64c1293
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
17 changed files with 586 additions and 42 deletions

View file

@ -1,5 +1,5 @@
import { betterAuth } from "better-auth";
import { username } from "better-auth/plugins";
import { username, admin } from "better-auth/plugins";
import dotenv from "dotenv";
import pg from "pg";
@ -7,7 +7,31 @@ dotenv.config();
type AuthType = ReturnType<typeof betterAuth> | null;
export let auth: AuthType | null = null;
export let auth: AuthType | null = 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,
}),
emailAndPassword: {
enabled: true,
},
deleteUser: {
enabled: true,
},
plugins: [username(), admin()],
trustedOrigins: [],
advanced: {
useSecureCookies: process.env.NODE_ENV === "production", // don't mark Secure in dev
defaultCookieAttributes: {
sameSite: process.env.NODE_ENV === "production" ? "none" : "lax",
path: "/",
},
},
});
export const initAuth = (allowList: string[]) => {
auth = betterAuth({
@ -25,7 +49,7 @@ export const initAuth = (allowList: string[]) => {
deleteUser: {
enabled: true,
},
plugins: [username()],
plugins: [username(), admin()],
trustedOrigins: allowList,
advanced: {
useSecureCookies: process.env.NODE_ENV === "production", // don't mark Secure in dev