"use client" import { useState } from "react" import { useRouter } from "next/navigation" import { isDesktop } from "@/lib/platform" export default function LoginPage() { const router = useRouter() const [token, setToken] = useState("") const [error, setError] = useState("") const [loading, setLoading] = useState(false) // Desktop users skip login entirely if (isDesktop()) { router.replace("/welcome") return null } async function handleSubmit(e: React.FormEvent) { e.preventDefault() setError("") setLoading(true) try { // Validate token by calling a lightweight API endpoint const res = await fetch("/api/health", { method: "POST", headers: { "Content-Type": "application/json", Authorization: `Bearer ${token}`, }, body: "{}", }) if (res.ok) { localStorage.setItem("codeg_token", token) router.replace("/welcome") } else if (res.status === 401) { setError("Token 无效,请检查后重试") } else { setError(`连接失败 (HTTP ${res.status})`) } } catch { setError("无法连接到服务器") } finally { setLoading(false) } } return (

Codeg

输入访问 Token 以连接到桌面端

setToken(e.target.value)} placeholder="Access Token" autoFocus className="flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring" />
{error && (

{error}

)}

Token 可在桌面端 设置 → Web 服务 中获取

) }