45 lines · 1.9 KBRaw
| 1 | import { Button, Input } from "@refs/design-system"; |
| 2 | import { MIN_PASSWORD_LENGTH } from "@refs/backend/contract"; |
| 3 | import { Form, Link, redirect, useNavigation } from "react-router"; |
| 4 | import type { Route } from "./+types/reset-password"; |
| 5 | import { AuthPage } from "../components/shell"; |
| 6 | import { failed, gate, sessionCookie } from "../lib/session"; |
| 7 | |
| 8 | export const meta: Route.MetaFunction = () => [{ title: "Choose a new password · refs" }, { name: "referrer", content: "no-referrer" }]; |
| 9 | |
| 10 | export async function action({ request, params, context }: Route.ActionArgs) { |
| 11 | const form = await request.formData(); |
| 12 | const outcome = await gate(context).resetPassword({ token: params.token, password: String(form.get("password") ?? "") }); |
| 13 | if (!outcome.ok) return failed(outcome.problem, {}); |
| 14 | throw redirect("/", { headers: { "Set-Cookie": sessionCookie(outcome.value) } }); |
| 15 | } |
| 16 | |
| 17 | export default function ResetPassword({ actionData }: Route.ComponentProps) { |
| 18 | const submitting = useNavigation().state === "submitting"; |
| 19 | return ( |
| 20 | <AuthPage subtitle="Choose a new password" error={actionData?.error}> |
| 21 | <Form method="post" className="flex flex-col gap-4"> |
| 22 | <Input |
| 23 | label="New password" |
| 24 | name="password" |
| 25 | type="password" |
| 26 | size="lg" |
| 27 | minLength={MIN_PASSWORD_LENGTH} |
| 28 | autoComplete="new-password" |
| 29 | description={`At least ${MIN_PASSWORD_LENGTH} characters. Your other sessions end.`} |
| 30 | required |
| 31 | autoFocus |
| 32 | /> |
| 33 | <Button type="submit" variant="primary" size="lg" className="w-full justify-center" loading={submitting}> |
| 34 | Set password |
| 35 | </Button> |
| 36 | <p className="m-0 text-center text-sm text-muted"> |
| 37 | Link expired?{" "} |
| 38 | <Link to="/forgot-password" className="text-accent-text"> |
| 39 | Send a new one |
| 40 | </Link> |
| 41 | </p> |
| 42 | </Form> |
| 43 | </AuthPage> |
| 44 | ); |
| 45 | } |