diff --git a/src/app/(full-width-pages)/(auth)/reset-password/page.tsx b/src/app/(full-width-pages)/(auth)/reset-password/page.tsx index edd8c89..6044c85 100644 --- a/src/app/(full-width-pages)/(auth)/reset-password/page.tsx +++ b/src/app/(full-width-pages)/(auth)/reset-password/page.tsx @@ -42,7 +42,7 @@ export default function ResetPasswordForm() { try { setLoading(true); - await apiCreateOTP(email); + await apiCreateOTP(email, 1); toast.success("Mã OTP đã được gửi đến email của bạn!"); setStep(2); } catch (error) { @@ -69,7 +69,7 @@ export default function ResetPasswordForm() { try { setLoading(true); - const verifyRes = await apiVerifyOTP(email, otp); + const verifyRes = await apiVerifyOTP(email, otp, 1); const tokenId = verifyRes?.data?.token_id; if (!tokenId) { diff --git a/src/components/auth/SignInForm.tsx b/src/components/auth/SignInForm.tsx index 9df2a0e..cb4ebe5 100644 --- a/src/components/auth/SignInForm.tsx +++ b/src/components/auth/SignInForm.tsx @@ -115,9 +115,10 @@ export default function SignInForm() { // Redirect back to the same origin (avoid hard-coded port/env mismatches). const redirectUrl = typeof window !== "undefined" ? window.location.origin : HOME_URL; - window.location.href = `${API.Auth.GOOGLE_LOGIN}?redirect=${encodeURIComponent( + const googleUrl = `${API.Auth.GOOGLE_LOGIN}?redirect=${encodeURIComponent( redirectUrl )}`; + router.push(googleUrl); }} className="inline-flex items-center justify-center gap-3 py-3 text-sm font-normal text-gray-700 transition-colors bg-gray-100 rounded-lg px-7 hover:bg-gray-200 hover:text-gray-800 dark:bg-white/5 dark:text-white/90 dark:hover:bg-white/10" > diff --git a/src/components/auth/SignUpForm.tsx b/src/components/auth/SignUpForm.tsx index 9e5a03e..04c6f57 100644 --- a/src/components/auth/SignUpForm.tsx +++ b/src/components/auth/SignUpForm.tsx @@ -166,9 +166,10 @@ export default function SignUpForm() { // Redirect back to the same origin (avoid hard-coded port/env mismatches). const redirectUrl = typeof window !== "undefined" ? window.location.origin : HOME_URL; - window.location.href = `${API.Auth.GOOGLE_LOGIN}?redirect=${encodeURIComponent( + const googleUrl = `${API.Auth.GOOGLE_LOGIN}?redirect=${encodeURIComponent( redirectUrl )}`; + router.push(googleUrl); }} className="inline-flex items-center justify-center gap-3 py-3 text-sm font-normal text-gray-700 transition-colors bg-gray-100 rounded-lg px-7 hover:bg-gray-200 hover:text-gray-800 dark:bg-white/5 dark:text-white/90 dark:hover:bg-white/10" > diff --git a/src/service/auth.ts b/src/service/auth.ts index ec8b37a..87161ef 100644 --- a/src/service/auth.ts +++ b/src/service/auth.ts @@ -2,8 +2,7 @@ import api from "@/config/config"; import { API } from "../../api"; import { clearStoredTokens, extractTokensFromResponsePayload, setStoredTokens } from "@/auth/tokenStore"; -export const apiCreateOTP = async (email: string) => { - const token_type = 2; +export const apiCreateOTP = async (email: string, token_type: number = 2) => { const response = await api.post(API.Auth.CREATEOTP, { email, token_type @@ -11,8 +10,8 @@ export const apiCreateOTP = async (email: string) => { return response.data; }; -export const apiVerifyOTP = async (email: string, token: string) => { - const body = { email, token, token_type: 2 }; +export const apiVerifyOTP = async (email: string, token: string, token_type: number = 2) => { + const body = { email, token, token_type }; const response = await api.post(API.Auth.VERIFYOTP, body); return response.data; };