chore: 密码重置界面
This commit is contained in:
parent
84239677f5
commit
d808aa3195
35
app/[lng]/request-reset/page.tsx
Normal file
35
app/[lng]/request-reset/page.tsx
Normal file
|
@ -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 (
|
||||
<div>
|
||||
<input
|
||||
type="email"
|
||||
placeholder="Your email"
|
||||
value={email}
|
||||
onChange={(e) => setEmail(e.target.value)}
|
||||
/>
|
||||
<button onClick={handleResetPassword}>Reset Password</button>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default RequestResetPassword;
|
41
app/[lng]/reset-password/page.tsx
Normal file
41
app/[lng]/reset-password/page.tsx
Normal file
|
@ -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 (
|
||||
<div>
|
||||
<input
|
||||
type="password"
|
||||
placeholder="New password"
|
||||
value={newPassword}
|
||||
onChange={(e) => setNewPassword(e.target.value)}
|
||||
/>
|
||||
<button onClick={handleNewPassword}>Update Password</button>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default ResetPassword;
|
Loading…
Reference in New Issue
Block a user