g1t/apps/web/app/routes/reset.tsx
Pick any line to see why it is the way it is: the commit, the pull request and issue it came from, and what the agent was thinking.
| Email verification, password reset, and Git for AI scale positioning | 1 | import { Form, Link, redirect } from "react-router"; |
| 2 | ||
| 3 | import type { Route } from "./+types/reset"; | |
| Social cards for every page: og.g1t.sh | 4 | import { page } from "../lib/meta"; |
| Email verification, password reset, and Git for AI scale positioning | 5 | import { AuthCard } from "../components/auth-card"; |
| 6 | import { Button, ErrorText, Field, Input } from "../components/ui"; | |
| 7 | import { identity } from "../lib/services.server"; | |
| 8 | import { assertSameOrigin } from "../lib/session.server"; | |
| 9 | ||
| Social cards for every page: og.g1t.sh | 10 | export function meta(args: Route.MetaArgs) { |
| 11 | return page(args, { title: "Choose a new password · g1t" }); | |
| Email verification, password reset, and Git for AI scale positioning | 12 | } |
| 13 | ||
| 14 | export function loader({ request }: Route.LoaderArgs) { | |
| 15 | return { token: new URL(request.url).searchParams.get("token") ?? "" }; | |
| 16 | } | |
| 17 | ||
| 18 | export async function action({ request }: Route.ActionArgs) { | |
| 19 | assertSameOrigin(request); | |
| 20 | const form = await request.formData(); | |
| 21 | const result = await identity.resetPassword( | |
| 22 | String(form.get("token") ?? ""), | |
| 23 | String(form.get("password") ?? ""), | |
| 24 | ); | |
| 25 | if (!result.ok) return { error: result.error.message }; | |
| 26 | throw redirect("/login?reset=1"); | |
| 27 | } | |
| 28 | ||
| 29 | export default function Reset({ loaderData, actionData }: Route.ComponentProps) { | |
| 30 | return ( | |
| 31 | <AuthCard | |
| 32 | title="Choose a new password" | |
| 33 | subtitle="You will be signed out everywhere" | |
| 34 | footer={ | |
| 35 | <Link to="/login" className="text-fg underline underline-offset-4"> | |
| 36 | Back to sign in | |
| 37 | </Link> | |
| 38 | } | |
| 39 | > | |
| 40 | <Form method="post" className="space-y-4"> | |
| 41 | <input type="hidden" name="token" value={loaderData.token} /> | |
| 42 | <Field label="New password" hint="At least 10 characters."> | |
| 43 | <Input | |
| 44 | name="password" | |
| 45 | type="password" | |
| 46 | autoComplete="new-password" | |
| 47 | required | |
| 48 | minLength={10} | |
| 49 | autoFocus | |
| 50 | /> | |
| 51 | </Field> | |
| 52 | <ErrorText>{actionData?.error}</ErrorText> | |
| 53 | <div className="pt-2 *:w-full"> | |
| 54 | <Button type="submit">Set password</Button> | |
| 55 | </div> | |
| 56 | </Form> | |
| 57 | </AuthCard> | |
| 58 | ); | |
| 59 | } |