feat(auth): add optional ALLOWED_EMAILS sign-in allowlist - #36
Merged
Conversation
A self-hosted instance on a public domain is open to signup: the email provider creates an account for whoever asks for a magic link, and that account gets its own workspace. On an instance run for a single operator that is worth closing. ALLOWED_EMAILS is a comma-separated, case-insensitive allowlist checked in the signIn callback, so a blocked address never even receives a magic link. Left unset the behaviour is unchanged, so existing deployments are not affected. The helper lives in lib/env.ts next to the other env accessors and reads the variable per call, matching getMetaGraphApiVersion, which keeps it testable with vi.stubEnv.
|
@paularro is attempting to deploy a commit to the diwenne's projects Team on Vercel. A member of the Team first needs to authorize it. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A self-hosted instance on a public domain is open to signup. The email provider creates an account for whoever asks for a magic link, and
events.createUsergives that account its own workspace. So anyone who finds the URL of an instance can register on it.That is the right default for a hosted product, but most people following
docs/setup.mdare running this for their own accounts, where it is just an open door. There is currently no way to close it short of putting the whole app behind basic auth, which breaks the webhook and the OAuth callback.Change
ALLOWED_EMAILS, a comma-separated, case-insensitive allowlist:Checked in the
signIncallback, which NextAuth runs before the magic link is sent, so a blocked address never receives one and noUserrow is created.Left unset, nothing changes. The helper returns
truewhen the list is empty, so existing deployments are unaffected and the variable is purely opt-in.The helper lives in
lib/env.tsnext to the other env accessors and readsprocess.envper call, matchinggetMetaGraphApiVersionrather than caching at module load. That is what makes it testable withvi.stubEnv.Also documents it in
.env.exampleand in the environment table indocs/setup.md.Tests
Five cases added to
__tests__/env.test.ts: unset list, list of only separators, listed vs unlisted address, case and whitespace on both sides, and a null/undefined/empty address while the list is set.tsc --noEmitandeslintclean.Behaviour when blocked
Verified against a live instance. A non-listed address redirects to
/api/auth/error?error=AccessDeniedand creates no user row; a listed address passes the callback and proceeds to the mail provider as normal.