Skip to content

Commit

Permalink
🔒 (auth) Block disposable emails during sign up
Browse files Browse the repository at this point in the history
  • Loading branch information
baptisteArno committed Jul 27, 2023
1 parent 320cffc commit abc3abd
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions apps/builder/src/pages/api/auth/[...nextauth].ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { getNewUserInvitations } from '@/features/auth/helpers/getNewUserInvitat
import { sendVerificationRequest } from '@/features/auth/helpers/sendVerificationRequest'
import { Ratelimit } from '@upstash/ratelimit'
import { Redis } from '@upstash/redis/nodejs'
import got from 'got'

const providers: Provider[] = []

Expand Down Expand Up @@ -172,6 +173,14 @@ export const authOptions: AuthOptions = {
signIn: async ({ account, user }) => {
if (!account) return false
const isNewUser = !('createdAt' in user && isDefined(user.createdAt))
if (isNewUser && user.email) {
const { body } = await got.get(
'https://raw.githubusercontent.com/disposable-email-domains/disposable-email-domains/master/disposable_email_blocklist.conf'
)
const disposableEmailDomains = body.split('\n')
if (disposableEmailDomains.includes(user.email.split('@')[1]))
return false
}
if (process.env.DISABLE_SIGNUP === 'true' && isNewUser && user.email) {
const { invitations, workspaceInvitations } =
await getNewUserInvitations(prisma, user.email)
Expand Down

0 comments on commit abc3abd

Please sign in to comment.