初始化web服务功能

This commit is contained in:
xintaofei
2026-03-25 14:26:26 +08:00
parent ae70f17d2e
commit ac09d3db9e
99 changed files with 3253 additions and 304 deletions

View File

@@ -2,11 +2,43 @@
import { useEffect } from "react"
import { useRouter } from "next/navigation"
import { isDesktop } from "@/lib/platform"
export default function Page() {
const router = useRouter()
useEffect(() => {
router.replace("/welcome")
if (isDesktop()) {
router.replace("/welcome")
return
}
// Web mode: validate token before entering app
const token = localStorage.getItem("codeg_token")
if (!token) {
router.replace("/login")
return
}
// Verify token is still valid
fetch("/api/health", {
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${token}`,
},
body: "{}",
})
.then((res) => {
if (res.ok) {
router.replace("/welcome")
} else {
localStorage.removeItem("codeg_token")
router.replace("/login")
}
})
.catch(() => {
// Server unreachable
localStorage.removeItem("codeg_token")
router.replace("/login")
})
}, [router])
return null
}