Small fix to next-auth-options (#7674)
This commit is contained in:
1 parent
229aeeb0c9
commit
14c38f5108
1 file changed
+15
-7
@@ -104,6 +104,11 @@ const providers: Provider[] = [
|
|||||||
throw new Error(ErrorCode.IncorrectUsernamePassword);
|
throw new Error(ErrorCode.IncorrectUsernamePassword);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const limiter = rateLimit({
|
||||||
|
intervalInMs: 60 * 1000, // 1 minute
|
||||||
|
});
|
||||||
|
await limiter.check(10, user.email); // 10 requests per minute
|
||||||
|
|
||||||
if (user.identityProvider !== IdentityProvider.CAL && !credentials.totpCode) {
|
if (user.identityProvider !== IdentityProvider.CAL && !credentials.totpCode) {
|
||||||
throw new Error(ErrorCode.ThirdPartyIdentityProviderEnabled);
|
throw new Error(ErrorCode.ThirdPartyIdentityProviderEnabled);
|
||||||
}
|
}
|
||||||
@@ -112,7 +117,10 @@ const providers: Provider[] = [
|
|||||||
throw new Error(ErrorCode.IncorrectUsernamePassword);
|
throw new Error(ErrorCode.IncorrectUsernamePassword);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (user.password) {
|
if (user.password || !credentials.totpCode) {
|
||||||
|
if (!user.password) {
|
||||||
|
throw new Error(ErrorCode.IncorrectUsernamePassword);
|
||||||
|
}
|
||||||
const isCorrectPassword = await verifyPassword(credentials.password, user.password);
|
const isCorrectPassword = await verifyPassword(credentials.password, user.password);
|
||||||
if (!isCorrectPassword) {
|
if (!isCorrectPassword) {
|
||||||
throw new Error(ErrorCode.IncorrectUsernamePassword);
|
throw new Error(ErrorCode.IncorrectUsernamePassword);
|
||||||
@@ -147,11 +155,6 @@ const providers: Provider[] = [
|
|||||||
throw new Error(ErrorCode.IncorrectTwoFactorCode);
|
throw new Error(ErrorCode.IncorrectTwoFactorCode);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const limiter = rateLimit({
|
|
||||||
intervalInMs: 60 * 1000, // 1 minute
|
|
||||||
});
|
|
||||||
await limiter.check(10, user.email); // 10 requests per minute
|
|
||||||
// Check if the user you are logging into has any active teams
|
// Check if the user you are logging into has any active teams
|
||||||
const hasActiveTeams =
|
const hasActiveTeams =
|
||||||
user.teams.filter((m: { team: { metadata: unknown } }) => {
|
user.teams.filter((m: { team: { metadata: unknown } }) => {
|
||||||
@@ -614,7 +617,12 @@ export const AUTH_OPTIONS: AuthOptions = {
|
|||||||
) {
|
) {
|
||||||
await prisma.user.update({
|
await prisma.user.update({
|
||||||
where: { email: existingUserWithEmail.email },
|
where: { email: existingUserWithEmail.email },
|
||||||
data: { password: null },
|
// also update email to the IdP email
|
||||||
|
data: {
|
||||||
|
password: null,
|
||||||
|
identityProvider: idP,
|
||||||
|
identityProviderId: String(user.id),
|
||||||
|
},
|
||||||
});
|
});
|
||||||
if (existingUserWithEmail.twoFactorEnabled) {
|
if (existingUserWithEmail.twoFactorEnabled) {
|
||||||
return loginWithTotp(existingUserWithEmail);
|
return loginWithTotp(existingUserWithEmail);
|
||||||
|
|||||||
Reference in new issue
Block a user