2023-07-12 13:26:34 -05:00
|
|
|
import SubmitButton from "@/components/SubmitButton";
|
2023-08-01 15:20:05 -05:00
|
|
|
import CenteredForm from "@/layouts/CenteredForm";
|
2023-07-12 13:26:34 -05:00
|
|
|
import { signIn } from "next-auth/react";
|
2023-07-13 19:42:04 -05:00
|
|
|
import Image from "next/image";
|
2023-07-12 13:26:34 -05:00
|
|
|
import Link from "next/link";
|
|
|
|
import { useState } from "react";
|
|
|
|
import { toast } from "react-hot-toast";
|
|
|
|
|
|
|
|
interface FormData {
|
|
|
|
email: string;
|
|
|
|
}
|
|
|
|
|
|
|
|
export default function Forgot() {
|
|
|
|
const [submitLoader, setSubmitLoader] = useState(false);
|
|
|
|
|
|
|
|
const [form, setForm] = useState<FormData>({
|
|
|
|
email: "",
|
|
|
|
});
|
|
|
|
|
|
|
|
async function loginUser() {
|
|
|
|
if (form.email !== "") {
|
|
|
|
setSubmitLoader(true);
|
|
|
|
|
|
|
|
const load = toast.loading("Sending login link...");
|
|
|
|
|
2023-07-12 15:34:05 -05:00
|
|
|
await signIn("email", {
|
2023-07-12 13:26:34 -05:00
|
|
|
email: form.email,
|
2023-07-12 15:34:05 -05:00
|
|
|
callbackUrl: "/",
|
2023-07-12 13:26:34 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
toast.dismiss(load);
|
|
|
|
|
|
|
|
setSubmitLoader(false);
|
|
|
|
|
2023-07-12 15:34:05 -05:00
|
|
|
toast.success("Login link sent.");
|
2023-07-12 13:26:34 -05:00
|
|
|
} else {
|
|
|
|
toast.error("Please fill out all the fields.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
2023-08-01 15:20:05 -05:00
|
|
|
<CenteredForm>
|
|
|
|
<div className="p-2 flex flex-col gap-3 justify-between sm:w-[30rem] w-80 bg-slate-50 rounded-2xl shadow-md border border-sky-100">
|
|
|
|
<p className="text-2xl text-black font-bold">Password Recovery</p>
|
|
|
|
<div>
|
|
|
|
<p className="text-md text-black">
|
|
|
|
Enter your Email so we can send you a link to recover your account.
|
|
|
|
Make sure to change your password in the profile settings
|
|
|
|
afterwards.
|
|
|
|
</p>
|
|
|
|
<p className="text-sm text-gray-500">
|
2023-08-01 15:31:30 -05:00
|
|
|
You wont get logged in if you haven't created an account yet.
|
2023-08-01 15:20:05 -05:00
|
|
|
</p>
|
|
|
|
</div>
|
2023-07-13 19:42:04 -05:00
|
|
|
<div>
|
2023-07-22 16:49:09 -05:00
|
|
|
<p className="text-sm text-sky-700 w-fit font-semibold mb-1">Email</p>
|
2023-07-12 13:26:34 -05:00
|
|
|
|
2023-07-13 19:42:04 -05:00
|
|
|
<input
|
|
|
|
type="text"
|
|
|
|
placeholder="johnny@example.com"
|
|
|
|
value={form.email}
|
|
|
|
onChange={(e) => setForm({ ...form, email: e.target.value })}
|
2023-07-22 16:49:09 -05:00
|
|
|
className="w-full rounded-md p-2 mx-auto border-sky-100 border-solid border outline-none focus:border-sky-700 duration-100"
|
2023-07-13 19:42:04 -05:00
|
|
|
/>
|
|
|
|
</div>
|
2023-07-12 13:26:34 -05:00
|
|
|
|
|
|
|
<SubmitButton
|
|
|
|
onClick={loginUser}
|
|
|
|
label="Send Login Link"
|
|
|
|
className="mt-2 w-full text-center"
|
|
|
|
loading={submitLoader}
|
|
|
|
/>
|
2023-07-13 19:42:04 -05:00
|
|
|
<div className="flex items-baseline gap-1 justify-center">
|
2023-07-22 16:49:09 -05:00
|
|
|
<Link href={"/login"} className="block text-sky-700 font-bold">
|
2023-07-13 19:42:04 -05:00
|
|
|
Go back
|
|
|
|
</Link>
|
|
|
|
</div>
|
2023-07-12 13:26:34 -05:00
|
|
|
</div>
|
2023-08-01 15:20:05 -05:00
|
|
|
</CenteredForm>
|
2023-07-12 13:26:34 -05:00
|
|
|
);
|
|
|
|
}
|