@devries-cameron20 / t3code Mirror · read-only
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 04:45 UTC

main
tsx 92 lines 3.15 KB
Raw
1 /** Sign in or create an account. Sessions come from Better Auth. */
2 import { useState } from "react";
3 import { getConnection, signIn, signUp, type User } from "../client.ts";
4 import { Button, ErrorBox, Input, RepoIcon } from "../components.tsx";
5
6 export const SignInPage = ({
7 onSignedIn,
8 onCancel,
9 }: {
10 onSignedIn: (user: User) => void;
11 onCancel: () => void;
12 }) => {
13 const [mode, setMode] = useState<"sign-in" | "sign-up">("sign-in");
14 const [name, setName] = useState("");
15 const [email, setEmail] = useState("");
16 const [password, setPassword] = useState("");
17 const [error, setError] = useState<unknown>(null);
18 const [busy, setBusy] = useState(false);
19 const connection = getConnection();
20
21 const submit = async () => {
22 setBusy(true);
23 setError(null);
24 try {
25 const user =
26 mode === "sign-up"
27 ? await signUp(connection, { name: name.trim(), email, password })
28 : await signIn(connection, { email, password });
29 onSignedIn(user);
30 } catch (cause) {
31 setError(cause);
32 } finally {
33 setBusy(false);
34 }
35 };
36
37 return (
38 <div className="mx-auto mt-24 max-w-md px-4">
39 <div className="mb-6 flex items-center justify-center gap-2 text-xl font-semibold">
40 <RepoIcon className="size-6" />
41 git service
42 </div>
43 <form
44 className="space-y-4 rounded-lg border border-border-muted bg-canvas-subtle p-6"
45 onSubmit={(event) => {
46 event.preventDefault();
47 void submit();
48 }}
49 >
50 {mode === "sign-up" && (
51 <label className="block space-y-1.5">
52 <span className="text-sm font-medium">Name</span>
53 <Input value={name} onChange={setName} placeholder="Dana" />
54 </label>
55 )}
56 <label className="block space-y-1.5">
57 <span className="text-sm font-medium">Email</span>
58 <Input value={email} onChange={setEmail} type="email" placeholder="dana@example.com" />
59 </label>
60 <label className="block space-y-1.5">
61 <span className="text-sm font-medium">Password</span>
62 <Input
63 value={password}
64 onChange={setPassword}
65 type="password"
66 placeholder="at least 8 characters"
67 />
68 </label>
69 {error != null && <ErrorBox error={error} />}
70 <div className="flex items-center justify-between gap-2">
71 <Button kind="primary" type="submit" disabled={busy || !email || password.length < 8}>
72 {busy ? "Working…" : mode === "sign-up" ? "Create account" : "Sign in"}
73 </Button>
74 <button
75 type="button"
76 className="cursor-pointer text-xs text-fg-muted hover:text-accent"
77 onClick={() => setMode(mode === "sign-up" ? "sign-in" : "sign-up")}
78 >
79 {mode === "sign-up" ? "Have an account? Sign in" : "New here? Create an account"}
80 </button>
81 </div>
82 <button
83 type="button"
84 className="cursor-pointer text-xs text-fg-muted hover:text-accent"
85 onClick={onCancel}
86 >
87 Browse public repositories without signing in
88 </button>
89 </form>
90 </div>
91 );
92 };