Require password before disable 2FA
This commit is contained in:
@@ -2,7 +2,7 @@ import { retrieveUserInformation } from "../security/users";
|
|||||||
import { useEffect, useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
import { Button, Image, Input } from "@nextui-org/react";
|
import { Button, Image, Input } from "@nextui-org/react";
|
||||||
import instance from "../security/http";
|
import instance from "../security/http";
|
||||||
import { checkTwoFactorStatus } from "../utilities";
|
import { checkTwoFactorStatus, popToast } from "../utilities";
|
||||||
import TwoFactorAuthenticationModule from "./TwoFactorAuthenticationModule";
|
import TwoFactorAuthenticationModule from "./TwoFactorAuthenticationModule";
|
||||||
|
|
||||||
export default function TwoFactorsAuthenticationSetupModule({
|
export default function TwoFactorsAuthenticationSetupModule({
|
||||||
@@ -16,6 +16,7 @@ export default function TwoFactorsAuthenticationSetupModule({
|
|||||||
const [isTwoFactorEnabled, setIsTwoFactorEnabled] = useState(false);
|
const [isTwoFactorEnabled, setIsTwoFactorEnabled] = useState(false);
|
||||||
const [setupQRBase64, setSetupQRBase64] = useState("");
|
const [setupQRBase64, setSetupQRBase64] = useState("");
|
||||||
const [setupBase32Secret, setSetupBase32Secret] = useState("");
|
const [setupBase32Secret, setSetupBase32Secret] = useState("");
|
||||||
|
const [userPassword, setUserPassword] = useState("");
|
||||||
|
|
||||||
const disableTwoFactor = async () => {
|
const disableTwoFactor = async () => {
|
||||||
instance
|
instance
|
||||||
@@ -23,7 +24,25 @@ export default function TwoFactorsAuthenticationSetupModule({
|
|||||||
id: userInformation.id,
|
id: userInformation.id,
|
||||||
})
|
})
|
||||||
.then(() => {
|
.then(() => {
|
||||||
setDisable2FAStepperCount(1);
|
setDisable2FAStepperCount(2);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
const verifyAccount = () => {
|
||||||
|
if (userPassword.length === 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
instance
|
||||||
|
.post("/users/login", {
|
||||||
|
verify: true,
|
||||||
|
email: userInformation.email,
|
||||||
|
password: userPassword,
|
||||||
|
})
|
||||||
|
.then(() => {
|
||||||
|
disableTwoFactor();
|
||||||
|
})
|
||||||
|
.catch(() => {
|
||||||
|
popToast("Invalid password", 2);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -37,8 +56,6 @@ export default function TwoFactorsAuthenticationSetupModule({
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const testTwoFactor = () => {};
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
retrieveUserInformation().then((response) => {
|
retrieveUserInformation().then((response) => {
|
||||||
setUserInformation(response);
|
setUserInformation(response);
|
||||||
@@ -76,7 +93,11 @@ export default function TwoFactorsAuthenticationSetupModule({
|
|||||||
your choice.
|
your choice.
|
||||||
</p>
|
</p>
|
||||||
{setupQRBase64 && (
|
{setupQRBase64 && (
|
||||||
<Image src={setupQRBase64} alt="2FA SETUP QR" />
|
<Image
|
||||||
|
className="shadow-medium"
|
||||||
|
src={setupQRBase64}
|
||||||
|
alt="2FA SETUP QR"
|
||||||
|
/>
|
||||||
)}
|
)}
|
||||||
<p>Or alternatively, manually enter the secret in the app:</p>
|
<p>Or alternatively, manually enter the secret in the app:</p>
|
||||||
<Input value={setupBase32Secret} readOnly />
|
<Input value={setupBase32Secret} readOnly />
|
||||||
@@ -145,7 +166,7 @@ export default function TwoFactorsAuthenticationSetupModule({
|
|||||||
variant="light"
|
variant="light"
|
||||||
color="danger"
|
color="danger"
|
||||||
onPress={() => {
|
onPress={() => {
|
||||||
disableTwoFactor();
|
setDisable2FAStepperCount(1);
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
Confirm
|
Confirm
|
||||||
@@ -157,6 +178,26 @@ export default function TwoFactorsAuthenticationSetupModule({
|
|||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
{disable2FAStepperCount === 1 && (
|
{disable2FAStepperCount === 1 && (
|
||||||
|
<div className="flex flex-col gap-4 w-full">
|
||||||
|
<p>Let's verify that it's you.</p>
|
||||||
|
<Input
|
||||||
|
type="password"
|
||||||
|
label="Password"
|
||||||
|
value={userPassword}
|
||||||
|
onValueChange={setUserPassword}
|
||||||
|
/>
|
||||||
|
<div className="w-full flex flex-row justify-end">
|
||||||
|
<Button
|
||||||
|
onPress={() => {
|
||||||
|
verifyAccount();
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
Continue
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
{disable2FAStepperCount === 2 && (
|
||||||
<div className="flex flex-col gap-4 w-full">
|
<div className="flex flex-col gap-4 w-full">
|
||||||
<p>2FA has been disabled.</p>
|
<p>2FA has been disabled.</p>
|
||||||
<div className="w-full flex flex-row justify-end">
|
<div className="w-full flex flex-row justify-end">
|
||||||
|
|||||||
@@ -209,6 +209,11 @@ router.post("/login", async (req, res) => {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (data.verify) {
|
||||||
|
res.status(200).json({ passedCheck: true });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
let userInfo = {
|
let userInfo = {
|
||||||
id: user.id,
|
id: user.id,
|
||||||
email: user.email,
|
email: user.email,
|
||||||
|
|||||||
Reference in New Issue
Block a user