debug: add extensive logging to login flow

This commit is contained in:
Gemini AI
2025-12-29 02:52:36 +04:00
Unverified
parent 52720b2e84
commit 127b6da6ff

View File

@@ -21,15 +21,36 @@ const LoginView: Component<LoginViewProps> = (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<LoginViewProps> = (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<LoginViewProps> = (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<LoginViewProps> = (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" })
}