web: allow changing primary 2fa method

This commit is contained in:
Abdullah Atta
2023-06-08 12:19:28 +05:00
committed by Abdullah Atta
parent 94cc3a6853
commit 8cb3cb6b19
2 changed files with 51 additions and 75 deletions

View File

@@ -297,7 +297,7 @@ function ChooseAuthenticator(props: ChooseAuthenticatorProps) {
) : (
false
)}
<Text variant="body" mt={1} sx={{ fontWeight: "normal" }}>
<Text as="div" variant="body" mt={1} sx={{ fontWeight: "normal" }}>
{auth.subtitle}
</Text>
</Text>

View File

@@ -373,81 +373,57 @@ function Settings() {
setGroups((g) => ({ ...g, mfa: !g.mfa }));
}}
/>
{groups.mfa &&
(user.mfa.isEnabled ? (
<>
<Button
variant="list"
onClick={async () => {
if (await verifyAccount()) {
await showMultifactorDialog(user.mfa.primaryMethod);
await refreshUser();
}
}}
>
<Tip
text={
user.mfa.secondaryMethod
? "Reconfigure fallback 2FA method"
: "Add fallback 2FA method"
}
tip="You can use the fallback 2FA method in case you are unable to login via the primary method."
/>
</Button>
{groups.mfa && (
<>
<Button
variant="list"
onClick={async () => {
if (await verifyAccount()) {
await showMultifactorDialog();
await refreshUser();
}
}}
>
<Tip
text={"Change primary 2FA method"}
tip={`Your current primary 2FA method is ${user.mfa.primaryMethod}.`}
/>
</Button>
<Button
variant="list"
onClick={async () => {
if (await verifyAccount()) {
await showMultifactorDialog(user.mfa.primaryMethod);
await refreshUser();
}
}}
>
<Tip
text={
user.mfa.secondaryMethod
? "Reconfigure fallback 2FA method"
: "Add fallback 2FA method"
}
tip="You can use the fallback 2FA method in case you are unable to login via the primary method."
/>
</Button>
<Button
variant="list"
onClick={async () => {
if (await verifyAccount()) {
await show2FARecoveryCodesDialog(
user.mfa.primaryMethod
);
await refreshUser();
}
}}
>
<Tip
text="View recovery codes"
tip={`Recovery codes can be used to login in case you cannot use any of the other 2FA methods. You have ${user.mfa.remainingValidCodes} recovery codes left.`}
/>
</Button>
<Button
variant="list"
onClick={async () => {
if (await verifyAccount()) {
await db.mfa.disable();
showToast(
"success",
"Two-factor authentication disabled."
);
await refreshUser();
}
}}
>
<Tip
text="Disable two-factor authentication"
tip="You can disable 2FA if you want to reset or change 2FA settings."
/>
</Button>
</>
) : (
<>
<Button
variant="list"
onClick={async () => {
if (await verifyAccount()) {
await showMultifactorDialog();
await refreshUser();
}
}}
>
<Tip
text="Enable two-factor authentication"
tip="Two-factor authentication adds an additional layer of security to your account by requiring more than just a password to sign in."
/>
</Button>
</>
))}
<Button
variant="list"
onClick={async () => {
if (await verifyAccount()) {
await show2FARecoveryCodesDialog(user.mfa.primaryMethod);
await refreshUser();
}
}}
>
<Tip
text="View recovery codes"
tip={`Recovery codes can be used to login in case you cannot use any of the other 2FA methods. You have ${user.mfa.remainingValidCodes} recovery codes left.`}
/>
</Button>
</>
)}
</>
)}
{isLoggedIn && (