38 lines
1.0 KiB
TypeScript
38 lines
1.0 KiB
TypeScript
import { betterAuth } from "better-auth"
|
|
import { prismaAdapter } from "better-auth/adapters/prisma"
|
|
import { db } from "../src/client"
|
|
|
|
const adminOrigin = process.env.CMS_ADMIN_ORIGIN ?? "http://localhost:3001"
|
|
const webOrigin = process.env.CMS_WEB_ORIGIN ?? "http://localhost:3000"
|
|
const registrationFlag = process.env.CMS_ADMIN_REGISTRATION_ENABLED
|
|
|
|
export const auth = betterAuth({
|
|
appName: "CMS Admin",
|
|
baseURL: process.env.BETTER_AUTH_URL ?? adminOrigin,
|
|
secret: process.env.BETTER_AUTH_SECRET ?? "dev-only-change-me-for-production",
|
|
trustedOrigins: [adminOrigin, webOrigin],
|
|
database: prismaAdapter(db, {
|
|
provider: "postgresql",
|
|
}),
|
|
emailAndPassword: {
|
|
enabled: true,
|
|
disableSignUp: registrationFlag === "false",
|
|
},
|
|
user: {
|
|
additionalFields: {
|
|
role: {
|
|
type: "string",
|
|
required: true,
|
|
defaultValue: "editor",
|
|
input: false,
|
|
},
|
|
isBanned: {
|
|
type: "boolean",
|
|
required: true,
|
|
defaultValue: false,
|
|
input: false,
|
|
},
|
|
},
|
|
},
|
|
})
|