diff --git a/src/modules/auth/auth.ts b/src/modules/auth/auth.ts index b7f103c..1855731 100644 --- a/src/modules/auth/auth.ts +++ b/src/modules/auth/auth.ts @@ -34,6 +34,24 @@ export function createPortalAuth({ // for type uuid". Generate real UUIDs so inserts (signUp, sessions, // verifications) match the schema. advanced: { database: { generateId: () => crypto.randomUUID() } }, + // `role` is a custom column on `users` (portalRole enum: ADMIN | EDITORIAL). + // Better Auth's parseUserOutput filters the session user to declared fields + // only, so without this the drizzle adapter selects `role` but it is then + // stripped from session.user — requireAdmin and the root redirect saw + // role === undefined and misrouted/blocked every admin. Declaring it makes + // Better Auth return it; input:false keeps it unsettable on signUp (the DB + // default / admin seed owns it), defaultValue matches the column default so + // inserts never send null into the NOT NULL enum column. + user: { + additionalFields: { + role: { + type: "string", + required: false, + defaultValue: "EDITORIAL", + input: false, + }, + }, + }, emailAndPassword: { enabled: true, requireEmailVerification: true,