diff --git a/client/pages/ResetPassword.tsx b/client/pages/ResetPassword.tsx index f2ce0ab7..4ff71bfc 100644 --- a/client/pages/ResetPassword.tsx +++ b/client/pages/ResetPassword.tsx @@ -21,19 +21,35 @@ export default function ResetPassword() { const [confirm, setConfirm] = useState(""); const [isLoading, setIsLoading] = useState(true); const [submitting, setSubmitting] = useState(false); + const [linkError, setLinkError] = useState(null); + const [resetEmail, setResetEmail] = useState(""); const navigate = useNavigate(); - const { updatePassword } = useAuth(); - const { error: toastError, success: toastSuccess } = useAethexToast(); + const { updatePassword, requestPasswordReset } = useAuth(); + const { error: toastError, success: toastSuccess, info: toastInfo } = useAethexToast(); useEffect(() => { let mounted = true; (async () => { try { - // Ensure recovery session is established from URL parameters + const hash = typeof window !== "undefined" ? window.location.hash.replace(/^#/, "") : ""; + const params = new URLSearchParams(hash); + const urlError = params.get("error"); + const urlErrorDesc = params.get("error_description"); + if (urlError) { + setLinkError(urlErrorDesc || "Reset link is invalid or has expired."); + return; + } try { await supabase.auth.exchangeCodeForSession(window.location.href); - } catch {} - await supabase.auth.getSession(); + } catch (e: any) { + setLinkError("Reset link is invalid or has expired."); + return; + } + const { data } = await supabase.auth.getSession(); + if (!data?.session) { + setLinkError("Reset link is invalid or has expired."); + return; + } } finally { if (mounted) setIsLoading(false); } @@ -92,51 +108,91 @@ export default function ResetPassword() {
- - - - Set a new password - - - Enter and confirm your new password - - - -
-
- + {linkError ? ( + + + Reset link expired + + {linkError || "The link is invalid or has expired. Request a new reset link."} + + + +
+ setPassword(e.target.value)} - placeholder="Enter a new password" - minLength={6} - required + id="resetEmail" + type="email" + value={resetEmail} + onChange={(e) => setResetEmail(e.target.value)} + placeholder="you@example.com" /> +
+ + +
-
- - setConfirm(e.target.value)} - placeholder="Re-enter your new password" - minLength={6} - required - /> -
- - -
-
+ + + ) : ( + + + + Set a new password + + + Enter and confirm your new password + + + +
+
+ + setPassword(e.target.value)} + placeholder="Enter a new password" + minLength={6} + required + /> +
+
+ + setConfirm(e.target.value)} + placeholder="Re-enter your new password" + minLength={6} + required + /> +
+ +
+
+
+ )}