feat: add BetterAuth authentication
- Add better-auth to backend and frontend - Create auth tables (users, sessions, accounts, verifications) - Mount BetterAuth handler on /api/auth/* - Protect GET /api/tasks with session auth - Add login page with email/password - Add invite route for creating users - Add logout button to header - Cross-subdomain cookies for .donovankelly.xyz - Fix page title to 'Hammer Queue' - Keep bearer token for admin mutations (separate from session auth) - Update docker-compose with BETTER_AUTH_SECRET and COOKIE_DOMAIN
This commit is contained in:
32
backend/src/lib/auth.ts
Normal file
32
backend/src/lib/auth.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
import { betterAuth } from "better-auth";
|
||||
import { drizzleAdapter } from "better-auth/adapters/drizzle";
|
||||
import { db } from "../db";
|
||||
import * as schema from "../db/schema";
|
||||
|
||||
export const auth = betterAuth({
|
||||
database: drizzleAdapter(db, {
|
||||
provider: "pg",
|
||||
schema: {
|
||||
user: schema.users,
|
||||
session: schema.sessions,
|
||||
account: schema.accounts,
|
||||
verification: schema.verifications,
|
||||
},
|
||||
}),
|
||||
emailAndPassword: {
|
||||
enabled: true,
|
||||
},
|
||||
advanced: {
|
||||
disableCSRFCheck: false,
|
||||
cookiePrefix: "hammer-queue",
|
||||
crossSubDomainCookies: {
|
||||
enabled: true,
|
||||
domain: process.env.COOKIE_DOMAIN || ".donovankelly.xyz",
|
||||
},
|
||||
},
|
||||
trustedOrigins: [
|
||||
"https://queue.donovankelly.xyz",
|
||||
"http://localhost:5173",
|
||||
],
|
||||
secret: process.env.BETTER_AUTH_SECRET,
|
||||
});
|
||||
Reference in New Issue
Block a user