Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: mfa infinite loop #77

Merged
merged 2 commits into from
Oct 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions frontend/src/components/MFAModal/MFACode.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@ type MFACodeProps = {

export default function MFACode({ handleStep }: MFACodeProps) {
const [code, setCode] = useState(["", "", "", "", "", ""]);
const { user } = useContext(AuthContext);
const { user,setUser } = useContext(AuthContext);

const handleSubmit = async () => {
// Handle submission logic here
console.log("Submitted code:", code.join(""));
const endpoint = user.mfaEnabled ? "/auth/2fa/disable" : "/auth/2fa/enable";
await api
.post(endpoint, { code: code.join("") }, { withCredentials: true })
.then((r) => {
if (r.status == 201) handleStep(2);
setUser({ ...user, mfaEnabled: !user.mfaEnabled });
})
.catch((e) => {
toast.error("Código inválido", {
Expand All @@ -29,6 +29,7 @@ export default function MFACode({ handleStep }: MFACodeProps) {
console.log(e);
});
};

const baseURL = process.env.NEXT_PUBLIC_API_URL;

return (
Expand Down
10 changes: 3 additions & 7 deletions frontend/src/components/MFAModal/MFASuccess.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
import { AuthContext } from "@/contexts/AuthContext";
import { useContext } from "react";

type MFASuccessProps = {
handleStep: (step: number) => void;
};

export default function MFASuccess({ handleStep }: MFASuccessProps) {
const { user, setUser } = useContext(AuthContext);
// TODO solve infinite loop
setUser({ ...user, mfaEnabled: !user.mfaEnabled });
export default function MFASuccess() {
const { user } = useContext(AuthContext);

return (
<>
<div className="mt-2">
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/MFAModal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export default function MFAModal() {
) : step === 1 ? (
<MFACode handleStep={handleStep} />
) : step === 2 ? (
<MFASuccess handleStep={handleStep} />
<MFASuccess />
) : null}
</Dialog.Panel>
</Transition.Child>
Expand Down
Loading