-
Notifications
You must be signed in to change notification settings - Fork 2
AUTH_ALLOWED_EMAILS: named sign-in exceptions, so the domain rule cannot become a lock-out #36
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,7 +9,7 @@ import { admin } from "better-auth/plugins/admin"; | |
| import { dataSubstrate, getDb } from "../db/client"; | ||
| import * as schema from "../db/schema/index"; | ||
| import { ac, roles } from "./permissions"; | ||
| import { allowedEmailDomain, isAllowedEmail } from "./roles"; | ||
| import { allowedEmailDomain, allowedEmails, isAllowedEmail } from "./roles"; | ||
| import { isSuperAdminFloor } from "./super-admins"; | ||
| import type { Db } from "../db/types"; | ||
|
|
||
|
|
@@ -104,6 +104,7 @@ export async function getAuth(): Promise<AuthInstance | null> { | |
| export function createAuth(db: Db) { | ||
| const secret = process.env.AUTH_SECRET || ""; | ||
| const domain = allowedEmailDomain(); | ||
| const namedExceptions = allowedEmails().length > 0; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
When Useful? React with 👍 / 👎. |
||
|
|
||
| return betterAuth({ | ||
| secret, | ||
|
|
@@ -119,7 +120,15 @@ export function createAuth(db: Db) { | |
| clientId: process.env.GOOGLE_CLIENT_ID || "", | ||
| clientSecret: process.env.GOOGLE_CLIENT_SECRET || "", | ||
| // UI hint + Better Auth's `hd` claim check. Not the control. | ||
| hd: domain, | ||
| // | ||
| // Dropped entirely once AUTH_ALLOWED_EMAILS names anybody, because | ||
| // `hd` is not only a hint to Google: Better Auth verifies the claim | ||
| // on the returned id token, and a personal account carries no `hd` | ||
| // at all. Left on, it would refuse every named exception before | ||
| // this app's own check ran — the allowlist would look configured | ||
| // and do nothing. The picker gets wider; the two enforcement | ||
| // points below do not move. | ||
| ...(namedExceptions ? {} : { hd: domain }), | ||
| }, | ||
| } | ||
| : {}, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Document this variable in the scoped v5 guidance and the Stage 3 deployment instructions: the former still says
AUTH_SUPER_ADMIN_EMAILSis the one remaining environment list, while the latter omitsAUTH_ALLOWED_EMAILSentirely. An operator following those canonical instructions cannot configure the off-domain floor that this change is intended to support, leaving the lock-out recovery procedure incomplete.AGENTS.md reference: v5/AGENTS.md:L109-L114
Useful? React with 👍 / 👎.