"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 (
输入访问 Token 以连接到桌面端
Token 可在桌面端 设置 → Web 服务 中获取