diff --git a/src/components/auth/AuthWrapper.tsx b/src/components/auth/AuthWrapper.tsx index b891ed7..bd22795 100644 --- a/src/components/auth/AuthWrapper.tsx +++ b/src/components/auth/AuthWrapper.tsx @@ -1,4 +1,4 @@ -import { useState } from "react"; +import { useState, useEffect } from "react"; import { Settings } from "../../lib/settings"; import Header from "../navigation/Header"; import LoginForm from "./LoginForm"; @@ -7,20 +7,47 @@ import { RefreshContext } from "../../lib/RefreshContext"; import TabView from "../TabView"; export default function AuthWrapper() { - const [isConfigured, setIsConfigured] = useState( - Boolean(Settings.getServiceUrl() && Settings.getAdminPassword()), - ); + const [isConfigured, setIsConfigured] = useState(false); + const [isLoading, setIsLoading] = useState(true); const [lastUpdate, setLastUpdate] = useState(Date.now()); - const handleLogout = () => { - Settings.clearSettings(); - setIsConfigured(false); + useEffect(() => { + async function checkConfiguration() { + try { + const serviceUrl = await Settings.getServiceUrl(); + const adminPassword = await Settings.getAdminPassword(); + setIsConfigured(Boolean(serviceUrl && adminPassword)); + } catch (error) { + console.error("Error checking configuration:", error); + setIsConfigured(false); + } finally { + setIsLoading(false); + } + } + checkConfiguration(); + }, [lastUpdate]); + + const handleLogout = async () => { + try { + await Settings.clearSettings(); + setIsConfigured(false); + } catch (error) { + console.error("Error during logout:", error); + } }; const refresh = () => { setLastUpdate(Date.now()); }; + if (isLoading) { + return ( +
Enter your PDS credentials to get started
+ {error && ( +