feat(auth): add better-auth core wiring for admin and db
This commit is contained in:
37
packages/db/prisma/better-auth.config.ts
Normal file
37
packages/db/prisma/better-auth.config.ts
Normal file
@@ -0,0 +1,37 @@
|
||||
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,
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
Reference in New Issue
Block a user