From 7c30ee0c3e1af084a877774d3429a0e27143bd97 Mon Sep 17 00:00:00 2001 From: Ephraim Atta-Duncan Date: Mon, 5 Jun 2023 14:47:10 +0000 Subject: [PATCH] Redirect to /login on password reset --- apps/web/components/reset-password.tsx | 28 ++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/apps/web/components/reset-password.tsx b/apps/web/components/reset-password.tsx index 27e214574..d4745ee24 100644 --- a/apps/web/components/reset-password.tsx +++ b/apps/web/components/reset-password.tsx @@ -1,3 +1,4 @@ +import { useState } from "react"; import Link from "next/link"; import { useRouter } from "next/router"; import { Button } from "@documenso/ui"; @@ -19,8 +20,10 @@ export default function ResetPassword(props: any) { const { register, formState, watch } = methods; const password = watch("password", ""); + const [resetSuccessful, setResetSuccessful] = useState(false); + const onSubmit = async (values: IResetPassword) => { - await toast.promise( + const response = await toast.promise( fetch(`/api/auth/reset-password`, { method: "POST", headers: { @@ -35,7 +38,12 @@ export default function ResetPassword(props: any) { } ); - console.log(values); + if (response.ok) { + setResetSuccessful(true); + setTimeout(() => { + router.push("/login"); + }, 2000); + } }; if (!token) { @@ -56,6 +64,22 @@ export default function ResetPassword(props: any) { ); } + if (resetSuccessful) { + return ( +
+
+
+ +

+ Reset Password +

+

Your password has been reset.

+
+
+
+ ); + } + return ( <>