diff --git a/src/pages/authentication/LoginPage.jsx b/src/pages/authentication/LoginPage.jsx index da3f4980..c9eb5e0d 100644 --- a/src/pages/authentication/LoginPage.jsx +++ b/src/pages/authentication/LoginPage.jsx @@ -19,11 +19,17 @@ const LoginPage = () => { const loginSchema = IsLoginWithOTP ? z.object({ - username: z.string().email({ message: "Valid email required" }), + username: z.string() + .trim() + .email({ message: "Valid email required" }), }) : z.object({ - username: z.string().email({ message: "Valid email required" }), - password: z.string().min(1, { message: "Password required" }), + username: z.string() + .trim() + .email({ message: "Valid email required" }), + password: z.string() + .trim() + .min(1, { message: "Password required" }), rememberMe: z.boolean(), }); @@ -41,20 +47,24 @@ const LoginPage = () => { setLoading(true); try { + const username = data.username.trim(); + const password = data.password?.trim(); + if (!IsLoginWithOTP) { const userCredential = { - username: data.username, - password: data.password, + username, + password, }; + const response = await AuthRepository.login(userCredential); localStorage.setItem("jwtToken", response.data.token); localStorage.setItem("refreshToken", response.data.refreshToken); setLoading(false); navigate("/dashboard"); } else { - await AuthRepository.sendOTP({ email: data.username }); + await AuthRepository.sendOTP({ email: username }); showToast("OTP has been sent to your email.", "success"); - localStorage.setItem("otpUsername", data.username); + localStorage.setItem("otpUsername", username); localStorage.setItem("otpSentTime", now.toString()); navigate("/auth/login-otp"); } @@ -64,6 +74,7 @@ const LoginPage = () => { } }; + useEffect(() => { const otpSentTime = localStorage.getItem("otpSentTime"); if (