Skip to content
refs
History
45 lines · 1.9 KBRaw
1import { Button, Input } from "@refs/design-system";
2import { MIN_PASSWORD_LENGTH } from "@refs/backend/contract";
3import { Form, Link, redirect, useNavigation } from "react-router";
4import type { Route } from "./+types/reset-password";
5import { AuthPage } from "../components/shell";
6import { failed, gate, sessionCookie } from "../lib/session";
7
8export const meta: Route.MetaFunction = () => [{ title: "Choose a new password · refs" }, { name: "referrer", content: "no-referrer" }];
9
10export 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
17export 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}