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

Function LoginPage

apps/host-selfhost/web/login.tsx:21–182  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

19// redeeming an invite — either the full /join/<code> link, or by entering the
20// code here ("Have an invite code?"), which forwards to the same join page.
21export const LoginPage = () => {
22 // Where to go after sign-in. The gate renders this page IN PLACE of the
23 // requested route without navigating, so the live location is what carries a
24 // deep link (`/connect/linear`) across sign-in — see `postLoginTarget`.
25 const postLogin = postLoginTarget(window.location);
26 const [mode, setMode] = useState<"signin" | "code">("signin");
27 const [email, setEmail] = useState("");
28 const [password, setPassword] = useState("");
29 const [code, setCode] = useState("");
30 const [error, setError] = useState<string | null>(null);
31 const [busy, setBusy] = useState(false);
32 const [ssoProviders, setSsoProviders] = useState<readonly SsoProvider[]>([]);
33
34 useEffect(() => {
35 let cancelled = false;
36 void fetchSsoProviders().then((providers) => {
37 if (!cancelled) setSsoProviders(providers);
38 });
39 return () => {
40 cancelled = true;
41 };
42 }, []);
43
44 const signIn = async (event: FormEvent) => {
45 event.preventDefault();
46 setBusy(true);
47 setError(null);
48 const result = await authClient.signIn.email({ email, password });
49 if (result.error) {
50 setBusy(false);
51 setError(result.error.message ?? "Sign in failed");
52 return;
53 }
54 window.location.href = postLogin;
55 };
56
57 const signInWithSso = async (providerId: string) => {
58 setBusy(true);
59 setError(null);
60 // Better Auth redirects the browser to the IdP; on callback it lands on
61 // `callbackURL`, so the deep-link target survives the round trip the same
62 // way it does for the email form's post-login navigation.
63 const result = await authClient.signIn.oauth2({
64 providerId,
65 callbackURL: postLogin,
66 });
67 if (result.error) {
68 setBusy(false);
69 setError(result.error.message ?? "Sign in failed");
70 }
71 };
72
73 const redeem = (event: FormEvent) => {
74 event.preventDefault();
75 const trimmed = code.trim();
76 if (!trimmed) return;
77 // Forward to the join page, which collects name/email/password and redeems.
78 window.location.href = `/join/${encodeURIComponent(trimmed)}`;

Callers

nothing calls this directly

Calls 4

postLoginTargetFunction · 0.90
fetchSsoProvidersFunction · 0.90
setPasswordFunction · 0.85
signInWithSsoFunction · 0.85

Tested by

no test coverage detected