Skip to content

Commit

Permalink
fix: mfa infinite loop (#77)
Browse files Browse the repository at this point in the history
* fix: mfa infinite loop

* Removes unused component parameter

---------

Co-authored-by: Juliano <[email protected]>
  • Loading branch information
iaurg and julianochoi authored Oct 4, 2023
1 parent 61dde7e commit ca809e4
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 10 deletions.
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

0 comments on commit ca809e4

Please sign in to comment.