Files
ProxMenux/AppImage/app/page.tsx

86 lines
2.2 KiB
TypeScript
Raw Normal View History

2025-09-28 23:51:06 +02:00
"use client"
2025-11-07 19:43:55 +01:00
import { useState, useEffect } from "react"
2025-09-28 23:09:31 +02:00
import { ProxmoxDashboard } from "../components/proxmox-dashboard"
2025-11-07 19:43:55 +01:00
import { Login } from "../components/login"
import { AuthSetup } from "../components/auth-setup"
import { getApiUrl } from "../lib/api-config"
2025-09-28 19:40:23 +02:00
2025-09-28 23:09:31 +02:00
export default function Home() {
2025-11-07 20:05:29 +01:00
const [authStatus, setAuthStatus] = useState<{
loading: boolean
authEnabled: boolean
authConfigured: boolean
authenticated: boolean
}>({
loading: true,
authEnabled: false,
authConfigured: false,
authenticated: false,
})
2025-11-07 19:43:55 +01:00
useEffect(() => {
checkAuthStatus()
}, [])
const checkAuthStatus = async () => {
try {
2025-11-07 20:05:29 +01:00
const token = localStorage.getItem("proxmenux-auth-token")
2025-11-07 19:43:55 +01:00
const response = await fetch(getApiUrl("/api/auth/status"), {
2025-11-07 20:05:29 +01:00
headers: token ? { Authorization: `Bearer ${token}` } : {},
2025-11-07 19:43:55 +01:00
})
const data = await response.json()
2025-11-07 20:05:29 +01:00
console.log("[v0] Auth status:", data)
2025-11-07 19:43:55 +01:00
2025-11-07 20:05:29 +01:00
const authenticated = data.auth_enabled ? data.authenticated : true
2025-11-07 19:43:55 +01:00
2025-11-07 20:05:29 +01:00
setAuthStatus({
loading: false,
authEnabled: data.auth_enabled,
authConfigured: data.auth_configured,
authenticated,
2025-11-07 19:43:55 +01:00
})
} catch (error) {
2025-11-07 20:05:29 +01:00
console.error("[v0] Failed to check auth status:", error)
setAuthStatus({
loading: false,
authEnabled: false,
authConfigured: false,
authenticated: true,
})
2025-11-07 19:43:55 +01:00
}
}
2025-11-07 20:05:29 +01:00
const handleAuthComplete = () => {
checkAuthStatus()
2025-11-07 19:43:55 +01:00
}
const handleLoginSuccess = () => {
2025-11-07 20:05:29 +01:00
checkAuthStatus()
2025-11-07 19:43:55 +01:00
}
2025-11-07 20:05:29 +01:00
if (authStatus.loading) {
2025-11-07 19:43:55 +01:00
return (
<div className="min-h-screen bg-background flex items-center justify-center">
2025-11-07 20:05:29 +01:00
<div className="text-center space-y-4">
2025-11-07 19:43:55 +01:00
<div className="animate-spin rounded-full h-12 w-12 border-b-2 border-primary mx-auto"></div>
2025-11-07 20:05:29 +01:00
<p className="text-muted-foreground">Loading...</p>
2025-11-07 19:43:55 +01:00
</div>
</div>
)
}
2025-11-07 20:05:29 +01:00
if (authStatus.authEnabled && !authStatus.authenticated) {
2025-11-07 19:43:55 +01:00
return <Login onLogin={handleLoginSuccess} />
}
2025-11-07 20:05:29 +01:00
// Show dashboard in all other cases
return (
<>
{!authStatus.authConfigured && <AuthSetup onComplete={handleAuthComplete} />}
<ProxmoxDashboard />
</>
)
2025-09-28 19:40:23 +02:00
}