import { createFileRoute, useNavigate } from "@tanstack/react-router"; import { z } from "zod"; import { resetPassword } from "~/fns/login"; import { useAction } from "~/hooks/use-action"; import { AuthCard } from "~/components/AuthCard"; import { Button } from "~/ui/Button"; import { TextField } from "~/ui/Field"; import { ErrorBanner } from "~/ui/Callout"; import { TextLink } from "~/ui/TextLink"; export const Route = createFileRoute("/reset-password")({ validateSearch: z.object({ token: z.string().optional() }), head: () => ({ meta: [{ title: "Choose a new password ยท gitfor" }] }), component: ResetPasswordPage, }); function ResetPasswordPage() { const { token } = Route.useSearch(); const navigate = useNavigate(); const action = useAction(resetPassword); if (!token) { return ( Request a new link ); } return (
{ event.preventDefault(); const password = String(new FormData(event.currentTarget).get("password") ?? ""); const result = await action.run({ data: { token, password } }); if (result) await navigate({ to: result.signedIn ? "/" : "/login" }); }} >
); }