From d808aa31951faa5f8b2bf7d8ddd9075761cf785d Mon Sep 17 00:00:00 2001 From: 14790897 <14790897abc@gmail.com> Date: Fri, 8 Mar 2024 19:56:57 +0800 Subject: [PATCH] =?UTF-8?q?chore:=20=E5=AF=86=E7=A0=81=E9=87=8D=E7=BD=AE?= =?UTF-8?q?=E7=95=8C=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/[lng]/request-reset/page.tsx | 35 ++++++++++++++++++++++++++ app/[lng]/reset-password/page.tsx | 41 +++++++++++++++++++++++++++++++ 2 files changed, 76 insertions(+) create mode 100644 app/[lng]/request-reset/page.tsx create mode 100644 app/[lng]/reset-password/page.tsx diff --git a/app/[lng]/request-reset/page.tsx b/app/[lng]/request-reset/page.tsx new file mode 100644 index 0000000..5ab3eb2 --- /dev/null +++ b/app/[lng]/request-reset/page.tsx @@ -0,0 +1,35 @@ +import { useState } from "react"; +import { supabase } from "@/utils/supabaseClient"; + +const RequestResetPassword = () => { + const [email, setEmail] = useState(""); + + const handleResetPassword = async () => { + const { data, error } = await supabase.auth.api.resetPasswordForEmail( + email, + { + redirectTo: `${window.location.origin}/reset-password`, // 确保这个URL是你重置密码页面的地址 + } + ); + + if (error) { + alert("Error sending password reset email: " + error.message); + } else { + alert("Please check your email for the password reset link"); + } + }; + + return ( +
+ setEmail(e.target.value)} + /> + +
+ ); +}; + +export default RequestResetPassword; diff --git a/app/[lng]/reset-password/page.tsx b/app/[lng]/reset-password/page.tsx new file mode 100644 index 0000000..903012b --- /dev/null +++ b/app/[lng]/reset-password/page.tsx @@ -0,0 +1,41 @@ +import { useState } from "react"; +import { supabase } from "@/utils/supabaseClient"; +import { useRouter } from "next/router"; + +const ResetPassword = () => { + const [newPassword, setNewPassword] = useState(""); + const router = useRouter(); + const { access_token } = router.query; // 获取URL中的access_token参数 + + const handleNewPassword = async () => { + if (!access_token) { + alert("Token is not provided or invalid"); + return; + } + + const { error } = await supabase.auth.api.updateUser(access_token, { + password: newPassword, + }); + + if (error) { + alert("Error resetting password: " + error.message); + } else { + alert("Your password has been reset successfully"); + router.push("/login"); // 导航到登录页面或其他页面 + } + }; + + return ( +
+ setNewPassword(e.target.value)} + /> + +
+ ); +}; + +export default ResetPassword;