fix: 2FA from CAL to GOOGLE (#10288)

* Fixing 2FA from CAL to GOOGLE

* Missing change

* Missing logic for converted providers

* Fixing edge case and applying feedback

* Leftovers
This commit is contained in:
Leo Giovanetti authored and GitHub committed 2023-07-21 09:32:03 +01:00
1 parent b49952b8d8
commit d1778fdce8
7 files changed
+37 -21

No files matched your search

@@ -115,7 +115,7 @@ const providers: Provider[] = [
throw new Error(ErrorCode.IncorrectEmailPassword);
}
if (user.password || !credentials.totpCode) {
if (user.password && !credentials.totpCode) {
if (!user.password) {
throw new Error(ErrorCode.IncorrectEmailPassword);
}
@@ -560,7 +560,7 @@ export const AUTH_OPTIONS: AuthOptions = {
console.error("Error while linking account of already existing user");
}
}
if (existingUser.twoFactorEnabled) {
if (existingUser.twoFactorEnabled && existingUser.identityProvider === idP) {
return loginWithTotp(existingUser);
} else {
return true;
@@ -600,7 +600,11 @@ export const AUTH_OPTIONS: AuthOptions = {
if (existingUserWithEmail) {
// if self-hosted then we can allow auto-merge of identity providers if email is verified
if (!hostedCal && existingUserWithEmail.emailVerified) {
if (
!hostedCal &&
existingUserWithEmail.emailVerified &&
existingUserWithEmail.identityProvider !== IdentityProvider.CAL
) {
if (existingUserWithEmail.twoFactorEnabled) {
return loginWithTotp(existingUserWithEmail);
} else {
@@ -147,7 +147,11 @@ const useTabs = () => {
tab.name = user?.name || "my_account";
tab.icon = undefined;
tab.avatar = avatar?.avatar || WEBAPP_URL + "/" + session?.data?.user?.username + "/avatar.png";
} else if (tab.href === "/settings/security" && user?.identityProvider === IdentityProvider.GOOGLE) {
} else if (
tab.href === "/settings/security" &&
user?.identityProvider === IdentityProvider.GOOGLE &&
!user?.twoFactorEnabled
) {
tab.children = tab?.children?.filter(
(childTab) => childTab.href !== "/settings/security/two-factor-auth"
);