From cc4512e98571937c51d4aeb1973eb8d024d49df4 Mon Sep 17 00:00:00 2001 From: Syu125 Date: Fri, 19 Apr 2024 21:47:39 -0700 Subject: [PATCH] Automatic sign-in after resetting password --- frontend/src/app/handlePasswordReset/page.tsx | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/frontend/src/app/handlePasswordReset/page.tsx b/frontend/src/app/handlePasswordReset/page.tsx index 7c4b060..509c5b4 100644 --- a/frontend/src/app/handlePasswordReset/page.tsx +++ b/frontend/src/app/handlePasswordReset/page.tsx @@ -4,7 +4,11 @@ import React, { useState } from "react"; import Image from "next/image"; import styles from "@/app/handlePasswordReset/page.module.css"; -import { verifyPasswordResetCode, confirmPasswordReset } from "firebase/auth"; +import { + verifyPasswordResetCode, + confirmPasswordReset, + signInWithEmailAndPassword, +} from "firebase/auth"; import { initFirebase } from "@/firebase/firebase"; import { useRedirectToHomeIfSignedIn } from "@/hooks/useRedirection"; import { useEffect } from "react"; @@ -91,12 +95,11 @@ const PasswordReset: React.FC = () => { if (actionCode != null) { verifyPasswordResetCode(auth, actionCode) .then((email) => { - const accountEmail = email; if (actionCode != null) { confirmPasswordReset(auth, actionCode, data.newPassword) .then((resp) => { console.log("Password has been reset"); - window.location.href = "/login"; + signInWithEmailAndPassword(auth, email, data.newPassword); }) .catch((error) => { console.error("Confirm password reset failed: " + error);