g1t/apps/web/app/routes/register.tsx

83 lines2,428 bytesCodeBlame

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.

API and MCP server, Rust identity service, registration, site redesign1import { Form, Link, redirect } from "react-router";
2
3import type { Route } from "./+types/register";
4import { AuthCard } from "../components/auth-card";
5import { Button, ErrorText, Field, Input } from "../components/ui";
6import { identity } from "../lib/services.server";
7import {
8 assertSameOrigin,
9 getViewer,
10 startSession,
11} from "../lib/session.server";
12
13export function meta({}: Route.MetaArgs) {
14 return [{ title: "Create an account · g1t" }];
15}
16
17export function loader({ context }: Route.LoaderArgs) {
18 if (getViewer(context)) throw redirect("/");
19 return null;
20}
21
22export async function action({ request }: Route.ActionArgs) {
23 assertSameOrigin(request);
24 const form = await request.formData();
25 const result = await identity.register(
26 String(form.get("username") ?? ""),
27 String(form.get("email") ?? ""),
28 String(form.get("password") ?? ""),
29 );
30 if (!result.ok) return { error: result.error.message };
31 throw redirect("/", {
32 headers: { "set-cookie": startSession(result.value.sessionToken) },
33 });
34}
35
36export default function Register({ actionData }: Route.ComponentProps) {
37 return (
38 <AuthCard
39 title="Create your account"
Email verification, password reset, and Git for AI scale positioning40 subtitle="Git for AI scale"
API and MCP server, Rust identity service, registration, site redesign41 footer={
42 <>
43 Already have an account?{" "}
44 <Link to="/login" className="text-fg underline underline-offset-4">
45 Sign in
46 </Link>
47 </>
48 }
49 >
50 <Form method="post" className="space-y-4">
51 <Field
52 label="Username"
53 hint="Lowercase letters, digits and hyphens. This is your namespace: g1t.sh/username."
54 >
55 <Input
56 name="username"
57 autoComplete="username"
58 required
59 autoFocus
60 maxLength={39}
61 pattern="[a-z0-9](?:[a-z0-9]|-(?=[a-z0-9]))*"
62 />
63 </Field>
64 <Field label="Email">
65 <Input name="email" type="email" autoComplete="email" required />
66 </Field>
67 <Field label="Password" hint="At least 10 characters.">
68 <Input
69 name="password"
70 type="password"
71 autoComplete="new-password"
72 required
73 minLength={10}
74 />
75 </Field>
76 <ErrorText>{actionData?.error}</ErrorText>
77 <div className="pt-2 *:w-full">
78 <Button type="submit">Create account</Button>
79 </div>
80 </Form>
81 </AuthCard>
82 );
83}