chore: 重置密码
This commit is contained in:
parent
5f3252da6e
commit
f63dd8865b
|
@ -1,16 +1,16 @@
|
||||||
|
"use client";
|
||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
import { supabase } from "@/utils/supabaseClient";
|
import { createClient } from "@/utils/supabase/client";
|
||||||
|
|
||||||
const RequestResetPassword = () => {
|
const RequestResetPassword = () => {
|
||||||
|
const supabase = createClient();
|
||||||
|
|
||||||
const [email, setEmail] = useState("");
|
const [email, setEmail] = useState("");
|
||||||
|
|
||||||
const handleResetPassword = async () => {
|
const handleResetPassword = async () => {
|
||||||
const { data, error } = await supabase.auth.api.resetPasswordForEmail(
|
const { data, error } = await supabase.auth.resetPasswordForEmail(email, {
|
||||||
email,
|
redirectTo: `${window.location.origin}/reset-password`, // 确保这个URL是你重置密码页面的地址
|
||||||
{
|
});
|
||||||
redirectTo: `${window.location.origin}/reset-password`, // 确保这个URL是你重置密码页面的地址
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
if (error) {
|
if (error) {
|
||||||
alert("Error sending password reset email: " + error.message);
|
alert("Error sending password reset email: " + error.message);
|
||||||
|
|
|
@ -1,8 +1,11 @@
|
||||||
|
"use client";
|
||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
import { supabase } from "@/utils/supabaseClient";
|
import { createClient } from "@/utils/supabase/client";
|
||||||
import { useRouter } from "next/router";
|
import { useRouter } from "next/router";
|
||||||
|
|
||||||
const ResetPassword = () => {
|
const ResetPassword = () => {
|
||||||
|
const supabase = createClient();
|
||||||
|
|
||||||
const [newPassword, setNewPassword] = useState("");
|
const [newPassword, setNewPassword] = useState("");
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const { access_token } = router.query; // 获取URL中的access_token参数
|
const { access_token } = router.query; // 获取URL中的access_token参数
|
||||||
|
@ -13,7 +16,7 @@ const ResetPassword = () => {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const { error } = await supabase.auth.api.updateUser(access_token, {
|
const { error } = await supabase.auth.updateUser(access_token, {
|
||||||
password: newPassword,
|
password: newPassword,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user