From 0742c4b05cd3cbc50bab4b65a88c5d4e1baab2d5 Mon Sep 17 00:00:00 2001 From: Muhammad Ibrahim Date: Wed, 1 Oct 2025 09:08:27 +0100 Subject: [PATCH] fixed TFA setting up and login redirect issue --- frontend/src/pages/Login.jsx | 7 +++---- frontend/src/pages/Profile.jsx | 1 + 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/frontend/src/pages/Login.jsx b/frontend/src/pages/Login.jsx index a0c76a3..5ad9cb5 100644 --- a/frontend/src/pages/Login.jsx +++ b/frontend/src/pages/Login.jsx @@ -22,6 +22,7 @@ const Login = () => { const emailId = useId(); const passwordId = useId(); const tokenId = useId(); + const { login, setAuthState } = useAuth(); const [isSignupMode, setIsSignupMode] = useState(false); const [formData, setFormData] = useState({ username: "", @@ -41,7 +42,6 @@ const Login = () => { const [signupEnabled, setSignupEnabled] = useState(false); const navigate = useNavigate(); - const { login, setAuthState } = useAuth(); // Check if signup is enabled useEffect(() => { @@ -130,9 +130,8 @@ const Login = () => { const response = await authAPI.verifyTfa(tfaUsername, tfaData.token); if (response.data?.token) { - // Store token and user data - localStorage.setItem("token", response.data.token); - localStorage.setItem("user", JSON.stringify(response.data.user)); + // Update AuthContext with the new authentication state + setAuthState(response.data.token, response.data.user); // Redirect to dashboard navigate("/"); diff --git a/frontend/src/pages/Profile.jsx b/frontend/src/pages/Profile.jsx index 50635f1..5fc7d68 100644 --- a/frontend/src/pages/Profile.jsx +++ b/frontend/src/pages/Profile.jsx @@ -529,6 +529,7 @@ const Profile = () => { // TFA Tab Component const TfaTab = () => { + const verificationTokenId = useId(); const [setupStep, setSetupStep] = useState("status"); // 'status', 'setup', 'verify', 'backup-codes' const [verificationToken, setVerificationToken] = useState(""); const [password, setPassword] = useState("");