-
-
Notifications
You must be signed in to change notification settings - Fork 376
feat: add USESEND_INVITE_ONLY flag for invite-restricted signup #398
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
base: main
Are you sure you want to change the base?
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 | ||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -116,6 +116,22 @@ export const authOptions: NextAuthOptions = { | |||||||||||||||||||||||||||||||||||
| isWaitlisted: user.isWaitlisted, | ||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||
| }), | ||||||||||||||||||||||||||||||||||||
| signIn: async ({ user }) => { | ||||||||||||||||||||||||||||||||||||
| if (env.USESEND_INVITE_ONLY !== "true") return true; | ||||||||||||||||||||||||||||||||||||
| if (!user.email) return false; | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| const existing = await db.user.findUnique({ | ||||||||||||||||||||||||||||||||||||
| where: { email: user.email }, | ||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||
| if (existing) return true; | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| if (env.ADMIN_EMAIL && user.email === env.ADMIN_EMAIL) return true; | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| const invites = await db.teamInvite.findMany({ | ||||||||||||||||||||||||||||||||||||
| where: { email: user.email }, | ||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||
| return invites.length > 0; | ||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||
| adapter: PrismaAdapter(db) as Adapter, | ||||||||||||||||||||||||||||||||||||
| pages: { | ||||||||||||||||||||||||||||||||||||
|
|
@@ -133,6 +149,14 @@ export const authOptions: NextAuthOptions = { | |||||||||||||||||||||||||||||||||||
| invitesAvailable = invites.length > 0; | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| if (env.USESEND_INVITE_ONLY === "waitlist" && !invitesAvailable) { | ||||||||||||||||||||||||||||||||||||
| await db.user.update({ | ||||||||||||||||||||||||||||||||||||
| where: { id: user.id }, | ||||||||||||||||||||||||||||||||||||
| data: { isBetaUser: true, isWaitlisted: true }, | ||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||
| return; | ||||||||||||||||||||||||||||||||||||
|
Comment on lines
+152
to
+157
Contributor
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. Preserve Line 152 waitlists every uninvited new user, including Suggested fix- if (env.USESEND_INVITE_ONLY === "waitlist" && !invitesAvailable) {
+ if (
+ env.USESEND_INVITE_ONLY === "waitlist" &&
+ !invitesAvailable &&
+ user.email?.trim().toLowerCase() !== env.ADMIN_EMAIL?.trim().toLowerCase()
+ ) {
await db.user.update({
where: { id: user.id },
data: { isBetaUser: true, isWaitlisted: true },
});
return;
}📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| if ( | ||||||||||||||||||||||||||||||||||||
| !env.NEXT_PUBLIC_IS_CLOUD || | ||||||||||||||||||||||||||||||||||||
| env.NODE_ENV === "development" || | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
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.
Normalize email before admin/invite gating checks.
Line 121 onward uses raw
user.emailfor equality and DB lookups. Mixed-case emails can fail matches and incorrectly block allowed sign-ins.Suggested fix
signIn: async ({ user }) => { if (env.USESEND_INVITE_ONLY !== "true") return true; - if (!user.email) return false; + const normalizedEmail = user.email?.trim().toLowerCase(); + if (!normalizedEmail) return false; const existing = await db.user.findUnique({ - where: { email: user.email }, + where: { email: normalizedEmail }, }); if (existing) return true; - if (env.ADMIN_EMAIL && user.email === env.ADMIN_EMAIL) return true; + if ( + env.ADMIN_EMAIL?.trim().toLowerCase() === normalizedEmail + ) return true; const invites = await db.teamInvite.findMany({ - where: { email: user.email }, + where: { email: normalizedEmail }, }); return invites.length > 0; },🤖 Prompt for AI Agents