import React from "react"; import Head from "next/head"; import Link from "next/link"; import { useRouter } from "next/router"; import { Button, Group, Paper, Stack, TextInput, Text, Anchor, PasswordInput } from "@mantine/core"; import { toast } from "react-hot-toast"; import Layout from "src/layout/Layout"; import { supabase } from "src/lib/api/supabase"; function ResetPassword() { const [loading, setLoading] = React.useState(false); const [password, setPassword] = React.useState(""); const [password2, setPassword2] = React.useState(""); const onSubmit = async (e: React.FormEvent) => { try { e.preventDefault(); setLoading(true); if (password !== password2) throw new Error("Passwords do not match"); const { error } = await supabase.auth.updateUser({ password }); if (error) throw new Error(error.message); toast.success("Successfully updated password!"); setTimeout(() => window.location.assign("/sign-in"), 2000); } catch (error) { if (error instanceof Error) toast.error(error.message); } finally { setLoading(false); } }; return ( Create New Password
setPassword(e.target.value)} required label="New Password" radius="sm" placeholder="∗∗∗∗∗∗∗∗∗∗∗" style={{ color: "black" }} /> setPassword2(e.target.value)} required label="Validate Password" radius="sm" placeholder="∗∗∗∗∗∗∗∗∗∗∗" style={{ color: "black" }} />
); } const ForgotPassword = () => { const { query } = useRouter(); const [loading, setLoading] = React.useState(false); const [email, setEmail] = React.useState(""); const [success, setSuccess] = React.useState(false); const isPasswordReset = query?.type === "recovery" && !query?.error; const onSubmit = async (e: React.FormEvent) => { try { e.preventDefault(); setLoading(true); const { error } = await supabase.auth.resetPasswordForEmail(email); if (error) throw new Error(error.message); setSuccess(true); } catch (error) { if (error instanceof Error) toast.error(error.message); console.error(error); } finally { setLoading(false); } }; return ( Reset Password - JSON Crack {isPasswordReset ? ( ) : ( Reset Password {success ? ( We've sent an email to you, please check your inbox. ) : (
setEmail(e.target.value)} required label="Email" placeholder="hello@herowand.com" radius="sm" style={{ color: "black" }} /> Don't have an account? Sign Up
)}
)}
); }; export default ForgotPassword;