fix(auth): highlight failed server connections

This commit is contained in:
2026-07-22 23:13:55 +08:00
parent b01928a5e4
commit a564d48154
5 changed files with 72 additions and 1 deletions

View File

@@ -94,6 +94,18 @@ export async function login(server: string, email: string, password: string): Pr
return { baseUrl, token: response.token }
}
export async function checkServerConnection(server: string, signal?: AbortSignal) {
try {
const response = await fetch(`${normalizeBaseUrl(server)}/api/v1/status`, { signal })
if (!response.ok) return false
const payload = await response.json() as { timestamp?: unknown }
return typeof payload.timestamp === 'string'
} catch (error) {
if (error instanceof DOMException && error.name === 'AbortError') throw error
return false
}
}
export async function fetchProjects(session: ApiSession) {
useSessionBase(session)
return request<Project[]>('/api/v1/projects', { token: session.token })