g1t/apps/web/app/routes/forgot.tsx
| 1 | import { Form, Link } from "react-router"; |
| 2 | |
| 3 | import type { Route } from "./+types/forgot"; |
| 4 | import { AuthCard } from "../components/auth-card"; |
| 5 | import { Button, Field, Input } from "../components/ui"; |
| 6 | import { identity } from "../lib/services.server"; |
| 7 | import { assertSameOrigin } from "../lib/session.server"; |
| 8 | |
| 9 | export function meta({}: Route.MetaArgs) { |
| 10 | return [{ title: "Reset your password · g1t" }]; |
| 11 | } |
| 12 | |
| 13 | export async function action({ request }: Route.ActionArgs) { |
| 14 | assertSameOrigin(request); |
| 15 | const form = await request.formData(); |
| 16 | await identity.requestPasswordReset(String(form.get("email") ?? "")); |
| 17 | return { sent: true }; |
| 18 | } |
| 19 | |
| 20 | export default function Forgot({ actionData }: Route.ComponentProps) { |
| 21 | return ( |
| 22 | <AuthCard |
| 23 | title="Forgot your password?" |
| 24 | subtitle="We will email you a link" |
| 25 | footer={ |
| 26 | <Link to="/login" className="text-fg underline underline-offset-4"> |
| 27 | Back to sign in |
| 28 | </Link> |
| 29 | } |
| 30 | > |
| 31 | {actionData?.sent ? ( |
| 32 | <p className="rounded-lg border border-line bg-surface p-4 text-sm leading-6"> |
| 33 | If that address has an account, a reset link is on its way. It works |
| 34 | for one hour. |
| 35 | </p> |
| 36 | ) : ( |
| 37 | <Form method="post" className="space-y-4"> |
| 38 | <Field label="Email"> |
| 39 | <Input name="email" type="email" autoComplete="email" required autoFocus /> |
| 40 | </Field> |
| 41 | <div className="pt-2 *:w-full"> |
| 42 | <Button type="submit">Send reset link</Button> |
| 43 | </div> |
| 44 | </Form> |
| 45 | )} |
| 46 | </AuthCard> |
| 47 | ); |
| 48 | } |