Files
euchre_camp/src/lib/auth.ts
T
david 28fecdfaad refactor: remove all SQLite code, standardize on PostgreSQL
- Remove database provider switching logic from prisma.ts and auth.ts
- Hardcode PostgreSQL as the only supported database
- Remove switch-database.js and use-dev-db.js scripts
- Remove Python utility scripts that used sqlite3 directly
- Update justfile to remove SQLite test targets
- Update package.json to remove db:switch script
- Update Dockerfile.ci-base to default to PostgreSQL
- Update .env.example to remove SQLite mention
- Update playwright.config.ts comments
- Update .gitignore to remove SQLite file patterns

This eliminates the root cause of test failures: the dev server and test
Prisma client were using different databases (PostgreSQL vs SQLite).
2026-05-02 04:09:37 -07:00

83 lines
2.0 KiB
TypeScript

import { betterAuth } from "better-auth";
import { prismaAdapter } from "better-auth/adapters/prisma";
import { prisma } from "./prisma";
import { testUtils } from "better-auth/plugins";
export const auth = betterAuth({
database: prismaAdapter(prisma, {
provider: "postgresql",
}),
emailAndPassword: {
enabled: true,
autoSignIn: true,
requireEmailVerification: false,
minPasswordLength: 8,
maxPasswordLength: 128,
},
secret: process.env.BETTER_AUTH_SECRET || process.env.NEXTAUTH_SECRET,
baseURL: process.env.BETTER_AUTH_URL || process.env.NEXTAUTH_URL || "http://localhost:3000/api/auth",
trustedOrigins: (() => {
const origins = [];
if (process.env.TRUSTED_ORIGINS) {
origins.push(...process.env.TRUSTED_ORIGINS.split(',').map(o => o.trim()));
}
if (process.env.BETTER_AUTH_URL) {
origins.push(process.env.BETTER_AUTH_URL);
}
if (process.env.NEXTAUTH_URL) {
origins.push(process.env.NEXTAUTH_URL);
}
origins.push(
"https://euchre.notsosm.art",
"http://euchre.notsosm.art",
"http://dhg.lol:51193",
"http://localhost:3000",
"http://127.0.0.1:3000",
"http://0.0.0.0:3000"
);
return [...new Set(origins.filter(o => o))];
})(),
session: {
cookieCache: {
enabled: false,
},
},
rateLimit: {
enabled: false,
},
databaseHooks: {
user: {
create: {
async after(user) {
const timestamp = Date.now();
const randomId = Math.random().toString(36).substring(2, 8);
const baseName = user.name || user.email.split('@')[0];
const uniqueName = `${baseName}-${timestamp}-${randomId}`;
const newPlayer = await prisma.player.create({
data: {
name: uniqueName,
normalizedName: uniqueName.toLowerCase(),
},
});
await prisma.user.update({
where: { id: user.id },
data: { playerId: newPlayer.id },
});
},
},
},
},
plugins: [
testUtils()
]
});