el.xwx.moe/pages/forgot.tsx

87 lines
2.4 KiB
TypeScript
Raw Normal View History

2023-07-12 13:26:34 -05:00
import SubmitButton from "@/components/SubmitButton";
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 (
<>
<div className="p-2 mt-10 mx-auto flex flex-col gap-3 justify-between sm:w-[28rem] w-80 bg-slate-50 rounded-md border border-sky-100">
2023-07-13 19:42:04 -05:00
<div className="flex flex-col gap-2 sm:flex-row justify-between items-center mb-5">
<Image
src="/linkwarden.png"
width={1694}
height={483}
alt="Linkwarden"
className="h-12 w-fit"
/>
<div className="text-center sm:text-right">
<p className="text-3xl text-sky-500">Password Reset</p>
2023-07-13 19:42:04 -05:00
</div>
2023-07-12 13:26:34 -05:00
</div>
2023-07-13 19:42:04 -05:00
<div>
<p className="text-sm text-sky-500 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 })}
className="w-full rounded-md p-2 mx-auto border-sky-100 border-solid border outline-none focus:border-sky-500 duration-100"
/>
<p className="text-md text-gray-500 mt-1">
Make sure to change your password in the profile settings
afterwards.
</p>
</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">
<Link href={"/login"} className="block text-sky-500 font-bold">
Go back
</Link>
</div>
2023-07-12 13:26:34 -05:00
</div>
</>
);
}