chore: 重置密码

This commit is contained in:
liuweiqing 2024-03-09 16:15:49 +08:00
parent 5f3252da6e
commit f63dd8865b
2 changed files with 12 additions and 9 deletions

View File

@ -1,16 +1,16 @@
"use client";
import { useState } from "react";
import { supabase } from "@/utils/supabaseClient";
import { createClient } from "@/utils/supabase/client";
const RequestResetPassword = () => {
const supabase = createClient();
const [email, setEmail] = useState("");
const handleResetPassword = async () => {
const { data, error } = await supabase.auth.api.resetPasswordForEmail(
email,
{
redirectTo: `${window.location.origin}/reset-password`, // 确保这个URL是你重置密码页面的地址
}
);
const { data, error } = await supabase.auth.resetPasswordForEmail(email, {
redirectTo: `${window.location.origin}/reset-password`, // 确保这个URL是你重置密码页面的地址
});
if (error) {
alert("Error sending password reset email: " + error.message);

View File

@ -1,8 +1,11 @@
"use client";
import { useState } from "react";
import { supabase } from "@/utils/supabaseClient";
import { createClient } from "@/utils/supabase/client";
import { useRouter } from "next/router";
const ResetPassword = () => {
const supabase = createClient();
const [newPassword, setNewPassword] = useState("");
const router = useRouter();
const { access_token } = router.query; // 获取URL中的access_token参数
@ -13,7 +16,7 @@ const ResetPassword = () => {
return;
}
const { error } = await supabase.auth.api.updateUser(access_token, {
const { error } = await supabase.auth.updateUser(access_token, {
password: newPassword,
});