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

301 lines11,530 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.

Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look1import { CheckCircle2, Ticket } from "lucide-react";
2import { Form, Link, data, redirect } from "react-router";
3
4import type { InvitePreview } from "@g1t/contracts";
API and MCP server, Rust identity service, registration, site redesign5
6import type { Route } from "./+types/register";
Social cards for every page: og.g1t.sh7import { page } from "../lib/meta";
API and MCP server, Rust identity service, registration, site redesign8import { AuthCard } from "../components/auth-card";
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look9import { ContinueWithGithub, OrDivider } from "../components/github";
status.g1t.sh with incident management, invites that land you in the workspace, settings as pages, usage without quotas10import { Honeypot } from "../components/honeypot";
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look11import { githubSignInEnabled } from "../lib/github.server";
Merge branch 'worktree-agent-a985c01f43538af01'12import { Avatar, Button, ErrorText, Field, Input, SubmitButton } from "../components/ui";
API and MCP server, Rust identity service, registration, site redesign13import { identity } from "../lib/services.server";
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look14import { cleanCode, looksAutomated } from "../lib/invites";
15import { clientKey, registrationMode } from "../lib/registration.server";
API and MCP server, Rust identity service, registration, site redesign16import {
17 assertSameOrigin,
18 getViewer,
Device sign-in replaces registering and minting tokens over the API19 nextPath,
API and MCP server, Rust identity service, registration, site redesign20 startSession,
21} from "../lib/session.server";
22
Social cards for every page: og.g1t.sh23export function meta(args: Route.MetaArgs) {
24 return page(args, { title: "Create an account · g1t" });
API and MCP server, Rust identity service, registration, site redesign25}
26
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look27export async function loader({ request, context }: Route.LoaderArgs) {
Device sign-in replaces registering and minting tokens over the API28 if (getViewer(context)) throw redirect(nextPath(request));
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look29 const inviteOnly = (await registrationMode()) !== "open";
30 const code = cleanCode(new URL(request.url).searchParams.get("invite"));
31 // The invite is checked before anything else on the page: without a good
32 // one, there is no form to fill in.
33 const checked = code ? await identity.checkInvite(code, clientKey(request)) : null;
34 const invite: InvitePreview | null = checked?.ok ? checked.value : null;
status.g1t.sh with incident management, invites that land you in the workspace, settings as pages, usage without quotas35 // A good invite is used on its own page, which knows whom it is from and
36 // where it leads; it signs up, joins and lands in one go.
37 if (invite && code) throw redirect(`/invite/${encodeURIComponent(code)}`);
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look38 // Signing up with GitHub carries the invite code and `next` through it.
39 const params = new URLSearchParams();
40 if (code) params.set("invite", code);
41 if (nextPath(request) !== "/") params.set("next", nextPath(request));
42 const query = params.toString();
43 return {
44 inviteOnly,
45 code,
46 invite,
47 inviteError: checked && !checked.ok ? checked.error.message : null,
48 github: await githubSignInEnabled(),
49 githubUrl: query ? `/auth/github?${query}` : "/auth/github",
50 started: Date.now(),
51 };
API and MCP server, Rust identity service, registration, site redesign52}
53
54export async function action({ request }: Route.ActionArgs) {
55 assertSameOrigin(request);
56 const form = await request.formData();
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look57 const client = clientKey(request);
58
59 if (form.get("intent") === "request-access") {
60 // A bot gets the same thanks as a person, and nothing is kept.
61 if (looksAutomated(form)) return { requested: true };
62 const result = await identity.requestAccess(
63 String(form.get("email") ?? ""),
64 String(form.get("about") ?? ""),
65 client,
66 );
67 if (!result.ok) return data({ requestError: result.error.message }, { status: 422 });
68 return { requested: true };
69 }
70
71 const code = cleanCode(String(form.get("invite") ?? ""));
72 if (looksAutomated(form)) return data({ error: "Something went wrong. Try again." }, { status: 422 });
73 // The invite first, so its problem is the one shown.
74 let joins: string | null = null;
75 if (code) {
76 const checked = await identity.checkInvite(code, client);
77 if (!checked.ok) return data({ error: checked.error.message }, { status: 422 });
78 joins = checked.value.workspace?.slug ?? null;
79 }
API and MCP server, Rust identity service, registration, site redesign80 const result = await identity.register(
81 String(form.get("username") ?? ""),
82 String(form.get("email") ?? ""),
83 String(form.get("password") ?? ""),
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look84 code || null,
85 client,
API and MCP server, Rust identity service, registration, site redesign86 );
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look87 if (!result.ok) return data({ error: result.error.message }, { status: 422 });
88 // An invite to a workspace lands in it; anything else goes where it was going.
89 const next = nextPath(request);
90 throw redirect(joins && next === "/" ? `/${joins}` : next, {
API and MCP server, Rust identity service, registration, site redesign91 headers: { "set-cookie": startSession(result.value.sessionToken) },
92 });
93}
94
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look95/** Who sent the invite and what it joins, above the form. */
96function InvitedBy({ invite }: { invite: InvitePreview }) {
97 const from = invite.invitedBy;
API and MCP server, Rust identity service, registration, site redesign98 return (
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look99 <div className="mb-6 flex items-center gap-3 rounded-lg border border-accent/30 bg-accent/5 p-3" role="status">
100 {invite.workspace ? (
101 <Avatar name={invite.workspace.slug} image={invite.workspace.avatar} size={36} square />
102 ) : from ? (
103 <Avatar name={from.username} image={from.avatar} size={36} />
104 ) : (
105 <span className="inline-flex size-9 shrink-0 items-center justify-center rounded-full bg-accent/15 text-accent">
106 <Ticket size={18} />
107 </span>
108 )}
109 <p className="min-w-0 text-sm leading-5">
110 {from ? (
111 <>
112 <span className="font-medium text-fg">{from.name ?? from.username}</span>
113 {from.name && <span className="font-mono text-muted"> @{from.username}</span>}
114 </>
115 ) : (
116 <span className="font-medium text-fg">The g1t team</span>
117 )}{" "}
118 <span className="text-muted">
119 invited you
120 {invite.workspace ? (
121 <>
122 {" "}to <span className="font-medium text-fg">{invite.workspace.name}</span>
123 </>
124 ) : (
125 " to g1t"
126 )}
127 .
128 </span>
129 </p>
130 </div>
131 );
132}
133
134function SignUpForm({
135 loaderData,
136 error,
137}: {
138 loaderData: Route.ComponentProps["loaderData"];
139 error: string | undefined;
140}) {
141 const { invite, code, inviteOnly } = loaderData;
142 return (
143 <>
144 {invite && <InvitedBy invite={invite} />}
145 {loaderData.github && (
API and MCP server, Rust identity service, registration, site redesign146 <>
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look147 <ContinueWithGithub href={loaderData.githubUrl} />
148 <OrDivider />
API and MCP server, Rust identity service, registration, site redesign149 </>
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look150 )}
151 <Form method="post" className="relative space-y-4">
152 <Honeypot started={loaderData.started} />
153 {inviteOnly || code ? (
154 <Field label="Invite code" hint={invite ? undefined : "From your invite link or email."}>
155 <span className="block font-mono">
156 <Input name="invite" defaultValue={code} required={inviteOnly} spellCheck={false} autoCapitalize="none" />
157 </span>
158 </Field>
159 ) : null}
API and MCP server, Rust identity service, registration, site redesign160 <Field
161 label="Username"
Agents as a team: lifecycle, merge queue, billing and a new shell162 hint="Lowercase letters, digits and hyphens. It is how you sign in and how others see you."
API and MCP server, Rust identity service, registration, site redesign163 >
164 <Input
165 name="username"
166 autoComplete="username"
167 required
168 autoFocus
169 maxLength={39}
170 pattern="[a-z0-9](?:[a-z0-9]|-(?=[a-z0-9]))*"
171 />
172 </Field>
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look173 <Field
174 label="Email"
175 hint={invite?.email ? `This invite is for ${invite.email}. Use that address.` : undefined}
176 >
API and MCP server, Rust identity service, registration, site redesign177 <Input name="email" type="email" autoComplete="email" required />
178 </Field>
179 <Field label="Password" hint="At least 10 characters.">
180 <Input
181 name="password"
182 type="password"
183 autoComplete="new-password"
184 required
185 minLength={10}
186 />
187 </Field>
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look188 <ErrorText>{error}</ErrorText>
API and MCP server, Rust identity service, registration, site redesign189 <div className="pt-2 *:w-full">
Merge branch 'worktree-agent-a985c01f43538af01'190 <SubmitButton pending="Creating account…">
191 {invite?.workspace ? `Create account and join ${invite.workspace.slug}` : "Create account"}
192 </SubmitButton>
API and MCP server, Rust identity service, registration, site redesign193 </div>
194 </Form>
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look195 </>
196 );
197}
198
199/** Invite-only and no good code: enter one, or ask for access. */
200function InviteOnly({
201 loaderData,
202 actionData,
203}: {
204 loaderData: Route.ComponentProps["loaderData"];
205 actionData: Route.ComponentProps["actionData"];
206}) {
207 const requested = actionData && "requested" in actionData;
208 return (
209 <div className="space-y-8">
210 <section id="invite" className="scroll-mt-24">
211 <h2 className="text-sm font-medium">Have an invite?</h2>
212 <p className="mt-1 text-sm text-muted">Paste the code or link from your invite.</p>
213 <Form method="get" className="mt-3 flex gap-2">
214 <div className="min-w-0 grow font-mono">
215 <Input
216 name="invite"
217 aria-label="Invite code"
218 placeholder="g1t-xxxx-xxxx-…"
219 defaultValue={loaderData.code}
220 required
221 spellCheck={false}
222 autoCapitalize="none"
223 />
224 </div>
225 <Button type="submit" variant="quiet">
226 Continue
227 </Button>
228 </Form>
229 {loaderData.inviteError && (
230 <div className="mt-2">
231 <ErrorText>{loaderData.inviteError}</ErrorText>
232 </div>
233 )}
234 </section>
235
236 <section id="request" className="scroll-mt-24 border-t border-line pt-8">
237 <h2 className="text-sm font-medium">Request access</h2>
238 {requested ? (
239 <p className="mt-3 flex items-start gap-2 rounded-md border border-accent/40 bg-surface p-3 text-sm" role="status">
240 <CheckCircle2 size={16} className="mt-0.5 shrink-0 text-accent" />
status.g1t.sh with incident management, invites that land you in the workspace, settings as pages, usage without quotas241 <span>
242 You are on the list, and your invite comes to that address when a place opens. The first time an address
243 asks, we email it to confirm.
244 </span>
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look245 </p>
246 ) : (
247 <>
248 <p className="mt-1 text-sm text-muted">
249 Leave your email and we will send an invite as we open up. Someone already on g1t can also invite you.
250 </p>
251 <Form method="post" className="relative mt-3 space-y-3">
252 <input type="hidden" name="intent" value="request-access" />
253 <Honeypot started={loaderData.started} />
254 <Field label="Email">
255 <Input name="email" type="email" autoComplete="email" required maxLength={254} />
256 </Field>
257 <Field label="What will you build? (optional)">
258 <textarea
259 name="about"
260 rows={3}
261 maxLength={1000}
262 className="w-full rounded-md border border-line bg-bg px-3 py-2 text-sm outline-none transition-colors placeholder:text-faint hover:border-line-strong focus:border-accent-dim"
263 />
264 </Field>
265 <ErrorText>{actionData && "requestError" in actionData ? actionData.requestError : undefined}</ErrorText>
266 <div className="*:w-full">
Merge branch 'worktree-agent-a985c01f43538af01'267 <SubmitButton pending="Sending…" match={{ intent: "request-access" }}>
268 Request access
269 </SubmitButton>
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look270 </div>
271 </Form>
272 </>
273 )}
274 </section>
275 </div>
276 );
277}
278
279export default function Register({ loaderData, actionData }: Route.ComponentProps) {
280 const { inviteOnly, invite } = loaderData;
281 const error = actionData && "error" in actionData ? actionData.error : undefined;
282 // Invite-only: the sign-up form only appears with a good code (or a
283 // submitted one that failed, so the person can correct the rest).
284 const showForm = !inviteOnly || invite !== null;
285 return (
286 <AuthCard
287 title={showForm ? "Create your account" : "g1t is invite-only for now"}
288 subtitle={showForm ? "Where people and agents ship software together" : "Enter your invite, or ask for one"}
289 footer={
290 <>
291 Already have an account?{" "}
292 <Link to="/login" className="text-fg underline underline-offset-4">
293 Sign in
294 </Link>
295 </>
296 }
297 >
298 {showForm ? <SignUpForm loaderData={loaderData} error={error} /> : <InviteOnly loaderData={loaderData} actionData={actionData} />}
API and MCP server, Rust identity service, registration, site redesign299 </AuthCard>
300 );
301}

This file's history is long; its oldest lines are credited to the oldest commit read.