debug: add extensive logging to login flow
This commit is contained in:
@@ -21,15 +21,36 @@ const LoginView: Component<LoginViewProps> = (props) => {
|
|||||||
const [isLoggingIn, setIsLoggingIn] = createSignal(false)
|
const [isLoggingIn, setIsLoggingIn] = createSignal(false)
|
||||||
const [isLoadingUsers, setIsLoadingUsers] = createSignal(true)
|
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[]) => {
|
const safeInvoke = async (method: string, ...args: any[]) => {
|
||||||
|
console.log(`[LoginView] safeInvoke(${method})...`)
|
||||||
const api = getApi()
|
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
|
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)
|
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 () => {
|
onMount(async () => {
|
||||||
@@ -55,6 +76,7 @@ const LoginView: Component<LoginViewProps> = (props) => {
|
|||||||
const handleLogin = async (e: Event) => {
|
const handleLogin = async (e: Event) => {
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
const name = username().trim()
|
const name = username().trim()
|
||||||
|
console.log("[LoginView] handleLogin called, name:", name)
|
||||||
if (!name) {
|
if (!name) {
|
||||||
toast.error("Identity required")
|
toast.error("Identity required")
|
||||||
return
|
return
|
||||||
@@ -62,13 +84,16 @@ const LoginView: Component<LoginViewProps> = (props) => {
|
|||||||
|
|
||||||
setIsLoggingIn(true)
|
setIsLoggingIn(true)
|
||||||
try {
|
try {
|
||||||
|
console.log("[LoginView] isElectronHost:", isElectronHost())
|
||||||
if (isElectronHost()) {
|
if (isElectronHost()) {
|
||||||
|
console.log("[LoginView] Fetching users...")
|
||||||
const userList = await safeInvoke("users:list")
|
const userList = await safeInvoke("users:list")
|
||||||
if (!userList || !Array.isArray(userList)) {
|
if (!userList || !Array.isArray(userList)) {
|
||||||
toast.error("Bridge failure: try restarting")
|
toast.error("Bridge failure: try restarting")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
console.log("[LoginView] Users found:", userList.map((u: any) => u.name))
|
||||||
const user = userList.find((u: UserRecord) => u.name.toLowerCase() === name.toLowerCase())
|
const user = userList.find((u: UserRecord) => u.name.toLowerCase() === name.toLowerCase())
|
||||||
|
|
||||||
if (!user) {
|
if (!user) {
|
||||||
@@ -76,19 +101,22 @@ const LoginView: Component<LoginViewProps> = (props) => {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
console.log("[LoginView] Attempting login for:", user.id)
|
||||||
const result = await safeInvoke("users:login", {
|
const result = await safeInvoke("users:login", {
|
||||||
id: user.id,
|
id: user.id,
|
||||||
password: password(),
|
password: password(),
|
||||||
})
|
})
|
||||||
|
|
||||||
|
console.log("[LoginView] Login result:", result)
|
||||||
if (result?.success) {
|
if (result?.success) {
|
||||||
toast.success(`Welcome back, ${result.user.name}!`)
|
toast.success(`Welcome back, ${result.user.name}!`)
|
||||||
setActiveUserId(result.user.id) // Proactively update local state
|
setActiveUserId(result.user.id)
|
||||||
props.onLoginSuccess(result.user)
|
props.onLoginSuccess(result.user)
|
||||||
} else {
|
} else {
|
||||||
toast.error("Invalid key for this identity")
|
toast.error("Invalid key for this identity")
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
console.log("[LoginView] Web mode login")
|
||||||
toast.success("Web mode access granted")
|
toast.success("Web mode access granted")
|
||||||
props.onLoginSuccess({ id: "web-user", name: "Web Explorer" })
|
props.onLoginSuccess({ id: "web-user", name: "Web Explorer" })
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user