defensive email verification check

This commit is contained in:
Thomas Ruoff
2022-10-14 23:00:56 +02:00
parent a500d6f76b
commit afa998bde7

View File

@@ -32,15 +32,15 @@ export default NextAuth({
callbacks: { callbacks: {
async signIn({ account, email }) { async signIn({ account, email }) {
// if user sigin requested magic link via EmailProvider // if user sigin requested magic link via EmailProvider
if (account.provider === 'email') { if (account?.provider === 'email') {
if (email.verificationRequest) { if (email?.verificationRequest) {
// only allow admins by email entered // only allow admins by email entered
return account.providerAccountId === ADMIN_EMAIL return account.providerAccountId === ADMIN_EMAIL
} }
// if user accesses with magic link, also only allow admin // if user accesses with magic link, also only allow admin
return account.providerAccountId === ADMIN_EMAIL return account.providerAccountId === ADMIN_EMAIL
} else if (account.provider === 'github') { } else if (account?.provider === 'github') {
// only one and only one user // only one and only one user
return GITHUB_USERS_GRANTED.includes(account.providerAccountId) return GITHUB_USERS_GRANTED.includes(account.providerAccountId)
} }