MCPcopy Create free account
hub / github.com/UsefulSoftwareCo/executor / JoinPage

Function JoinPage

apps/host-selfhost/web/routes/public/join.$code.tsx:20–154  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

18// the new user into the org as a member. The root renders this outside the
19// auth gate (an un-redeemed visitor has no session yet).
20function JoinPage() {
21 const { code } = Route.useParams();
22 const [inviteState, setInviteState] = useState<"checking" | "valid" | "invalid">("checking");
23 const [name, setName] = useState("");
24 const [email, setEmail] = useState("");
25 const [password, setPassword] = useState("");
26 const [error, setError] = useState<string | null>(null);
27 const [busy, setBusy] = useState(false);
28
29 useEffect(() => {
30 let alive = true;
31 setInviteState("checking");
32 void fetch(`/api/invite-status/${encodeURIComponent(code)}`, {
33 credentials: "same-origin",
34 }).then(
35 async (response) => {
36 const body = response.ok
37 ? ((await response.json().then(
38 (value) => value,
39 () => ({}),
40 )) as { valid?: boolean })
41 : {};
42 if (alive) setInviteState(body.valid === true ? "valid" : "invalid");
43 },
44 () => {
45 if (alive) setInviteState("invalid");
46 },
47 );
48 return () => {
49 alive = false;
50 };
51 }, [code]);
52
53 const submit = async (event: FormEvent) => {
54 event.preventDefault();
55 setBusy(true);
56 setError(null);
57 // The Better Auth client forwards `inviteCode` (a non-schema field) onto the
58 // signup body the create gate reads; same-origin, so the session cookie
59 // sticks. Returns `{ error }` rather than throwing — no manual fetch.
60 const result = await authClient.signUp.email({ name, email, password, inviteCode: code });
61 if (result.error) {
62 setBusy(false);
63 setError(
64 result.error.message ??
65 "Could not create your account. Check your invite link and try again.",
66 );
67 return;
68 }
69 window.location.href = "/";
70 };
71
72 if (inviteState === "checking") {
73 return (
74 <div className="flex min-h-screen items-center justify-center text-sm text-muted-foreground">
75 Loading…
76 </div>
77 );

Callers

nothing calls this directly

Calls 3

setPasswordFunction · 0.85
jsonMethod · 0.65
fetchFunction · 0.50

Tested by

no test coverage detected