From 127b6da6ff69bb5ebd59afcd34aec53f01bc3a98 Mon Sep 17 00:00:00 2001 From: Gemini AI Date: Mon, 29 Dec 2025 02:52:36 +0400 Subject: [PATCH] debug: add extensive logging to login flow --- packages/ui/src/components/auth/LoginView.tsx | 38 ++++++++++++++++--- 1 file changed, 33 insertions(+), 5 deletions(-) diff --git a/packages/ui/src/components/auth/LoginView.tsx b/packages/ui/src/components/auth/LoginView.tsx index 9c43346..6a2662c 100644 --- a/packages/ui/src/components/auth/LoginView.tsx +++ b/packages/ui/src/components/auth/LoginView.tsx @@ -21,15 +21,36 @@ const LoginView: Component = (props) => { const [isLoggingIn, setIsLoggingIn] = createSignal(false) const [isLoadingUsers, setIsLoadingUsers] = createSignal(true) - const getApi = () => (window as any).electronAPI || (window as any).electron + const getApi = () => { + const api = (window as any).electronAPI || (window as any).electron + console.log("[LoginView] getApi:", api ? "found" : "null") + return api + } const safeInvoke = async (method: string, ...args: any[]) => { + console.log(`[LoginView] safeInvoke(${method})...`) const api = getApi() - if (!api) return null + if (!api) { + console.error("[LoginView] No API bridge!") + toast.error("System bridge unavailable") + return null + } const invoke = api.invoke || api.ipcRenderer?.invoke || (window as any).ipcRenderer?.invoke - if (!invoke) return null + if (!invoke) { + console.error("[LoginView] No invoke method!") + toast.error("IPC method missing") + return null + } const binder = api.invoke ? api : (api.ipcRenderer || (window as any).ipcRenderer) - return await invoke.call(binder, method, ...args) + try { + const result = await invoke.call(binder, method, ...args) + console.log(`[LoginView] safeInvoke(${method}) =>`, result) + return result + } catch (e) { + console.error(`[LoginView] safeInvoke(${method}) error:`, e) + toast.error(`IPC error: ${String(e)}`) + return null + } } onMount(async () => { @@ -55,6 +76,7 @@ const LoginView: Component = (props) => { const handleLogin = async (e: Event) => { e.preventDefault() const name = username().trim() + console.log("[LoginView] handleLogin called, name:", name) if (!name) { toast.error("Identity required") return @@ -62,13 +84,16 @@ const LoginView: Component = (props) => { setIsLoggingIn(true) try { + console.log("[LoginView] isElectronHost:", isElectronHost()) if (isElectronHost()) { + console.log("[LoginView] Fetching users...") const userList = await safeInvoke("users:list") if (!userList || !Array.isArray(userList)) { toast.error("Bridge failure: try restarting") return } + console.log("[LoginView] Users found:", userList.map((u: any) => u.name)) const user = userList.find((u: UserRecord) => u.name.toLowerCase() === name.toLowerCase()) if (!user) { @@ -76,19 +101,22 @@ const LoginView: Component = (props) => { return } + console.log("[LoginView] Attempting login for:", user.id) const result = await safeInvoke("users:login", { id: user.id, password: password(), }) + console.log("[LoginView] Login result:", result) if (result?.success) { toast.success(`Welcome back, ${result.user.name}!`) - setActiveUserId(result.user.id) // Proactively update local state + setActiveUserId(result.user.id) props.onLoginSuccess(result.user) } else { toast.error("Invalid key for this identity") } } else { + console.log("[LoginView] Web mode login") toast.success("Web mode access granted") props.onLoginSuccess({ id: "web-user", name: "Web Explorer" }) }