()
| 17 | // redeeming an invite — either the full /join/<code> link, or by entering the |
| 18 | // code here ("Have an invite code?"), which forwards to the same join page. |
| 19 | export const LoginPage = () => { |
| 20 | const search = window.location.search; |
| 21 | // Where to go after sign-in: resume an interrupted MCP OAuth authorize if we |
| 22 | // arrived from one (Better Auth redirects it here with the OAuth params), |
| 23 | // otherwise honor a safe returnTo (e.g. an integration OAuth callback), else |
| 24 | // land on the dashboard. |
| 25 | const postLogin = |
| 26 | mcpAuthorizeResumeTarget(search) ?? |
| 27 | safeReturnTo(new URLSearchParams(search).get("returnTo")) ?? |
| 28 | "/"; |
| 29 | const [mode, setMode] = useState<"signin" | "code">("signin"); |
| 30 | const [email, setEmail] = useState(""); |
| 31 | const [password, setPassword] = useState(""); |
| 32 | const [code, setCode] = useState(""); |
| 33 | const [error, setError] = useState<string | null>(null); |
| 34 | const [busy, setBusy] = useState(false); |
| 35 | |
| 36 | const signIn = async (event: FormEvent) => { |
| 37 | event.preventDefault(); |
| 38 | setBusy(true); |
| 39 | setError(null); |
| 40 | const result = await authClient.signIn.email({ email, password }); |
| 41 | if (result.error) { |
| 42 | setBusy(false); |
| 43 | setError(result.error.message ?? "Sign in failed"); |
| 44 | return; |
| 45 | } |
| 46 | window.location.href = postLogin; |
| 47 | }; |
| 48 | |
| 49 | const redeem = (event: FormEvent) => { |
| 50 | event.preventDefault(); |
| 51 | const trimmed = code.trim(); |
| 52 | if (!trimmed) return; |
| 53 | // Forward to the join page, which collects name/email/password and redeems. |
| 54 | window.location.href = `/join/${encodeURIComponent(trimmed)}`; |
| 55 | }; |
| 56 | |
| 57 | return ( |
| 58 | <AuthLayout> |
| 59 | <div className="w-full max-w-sm space-y-4 rounded-xl border border-border bg-card p-6 shadow-sm"> |
| 60 | <div className="space-y-1"> |
| 61 | <h1 className="text-xl font-semibold tracking-tight text-foreground"> |
| 62 | {mode === "signin" ? "Sign in" : "Join this instance"} |
| 63 | </h1> |
| 64 | <p className="text-sm text-muted-foreground"> |
| 65 | {mode === "signin" |
| 66 | ? "Welcome back. Use your instance account." |
| 67 | : "Enter the invite code you were given."} |
| 68 | </p> |
| 69 | </div> |
| 70 | |
| 71 | {mode === "signin" ? ( |
| 72 | <form onSubmit={signIn} className="space-y-4"> |
| 73 | <div className="space-y-1.5"> |
| 74 | <Label htmlFor="email">Email</Label> |
| 75 | <Input |
| 76 | id="email" |
nothing calls this directly
no test coverage detected