Skip to content

Where people and agents ship software together. The open-source git platform for the whole job: issues, agents, checks and deploys to the edge.

49 linesCodeBlameRaw
1import { Form, Link, redirect } from "react-router";
2
3import type { Route } from "./+types/reset";
4import { page } from "../lib/meta";
5import { AuthCard } from "../components/auth-card";
6import { ErrorText, Field, Input, SubmitButton } from "../components/ui";
7import { identity } from "../lib/services.server";
8import { assertSameOrigin } from "../lib/session.server";
9
10export function meta(args: Route.MetaArgs) {
11 return page(args, { title: "Choose a new password · g1t" });
12}
13
14export function loader({ request }: Route.LoaderArgs) {
15 return { token: new URL(request.url).searchParams.get("token") ?? "" };
16}
17
18export async function action({ request }: Route.ActionArgs) {
19 assertSameOrigin(request);
20 const form = await request.formData();
21 const result = await identity.resetPassword(String(form.get("token") ?? ""), String(form.get("password") ?? ""));
22 if (!result.ok) return { error: result.error.message };
23 throw redirect("/login?reset=1");
24}
25
26export default function Reset({ loaderData, actionData }: Route.ComponentProps) {
27 return (
28 <AuthCard
29 title="Choose a new password"
30 subtitle="You will be signed out everywhere"
31 footer={
32 <Link to="/login" className="text-fg underline underline-offset-4">
33 Back to sign in
34 </Link>
35 }
36 >
37 <Form method="post" className="space-y-4">
38 <input type="hidden" name="token" value={loaderData.token} />
39 <Field label="New password" hint="At least 10 characters.">
40 <Input name="password" type="password" autoComplete="new-password" required minLength={10} autoFocus />
41 </Field>
42 <ErrorText>{actionData?.error}</ErrorText>
43 <div className="pt-2 *:w-full">
44 <SubmitButton pending="Saving…">Set password</SubmitButton>
45 </div>
46 </Form>
47 </AuthCard>
48 );
49}