fix: use correct preload API methods (listUsers, loginUser, getActiveUser)
Some checks failed
Release Binaries / release (push) Has been cancelled
Some checks failed
Release Binaries / release (push) Has been cancelled
This commit is contained in:
@@ -22,52 +22,35 @@ const LoginView: Component<LoginViewProps> = (props) => {
|
|||||||
const [isLoadingUsers, setIsLoadingUsers] = createSignal(true)
|
const [isLoadingUsers, setIsLoadingUsers] = createSignal(true)
|
||||||
|
|
||||||
const getApi = () => {
|
const getApi = () => {
|
||||||
const api = (window as any).electronAPI || (window as any).electron
|
const api = (window as any).electronAPI
|
||||||
console.log("[LoginView] getApi:", api ? "found" : "null")
|
console.log("[LoginView] getApi:", api ? Object.keys(api) : "null")
|
||||||
return api
|
return api
|
||||||
}
|
}
|
||||||
|
|
||||||
const safeInvoke = async (method: string, ...args: any[]) => {
|
|
||||||
console.log(`[LoginView] safeInvoke(${method})...`)
|
|
||||||
const api = getApi()
|
|
||||||
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) {
|
|
||||||
console.error("[LoginView] No invoke method!")
|
|
||||||
toast.error("IPC method missing")
|
|
||||||
return null
|
|
||||||
}
|
|
||||||
const binder = api.invoke ? api : (api.ipcRenderer || (window as any).ipcRenderer)
|
|
||||||
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 () => {
|
||||||
|
console.log("[LoginView] onMount, isElectronHost:", isElectronHost())
|
||||||
try {
|
try {
|
||||||
if (isElectronHost()) {
|
if (isElectronHost()) {
|
||||||
const userList = await safeInvoke("users:list")
|
const api = getApi()
|
||||||
|
if (api && api.listUsers) {
|
||||||
|
const userList = await api.listUsers()
|
||||||
|
console.log("[LoginView] listUsers result:", userList)
|
||||||
if (userList && Array.isArray(userList)) {
|
if (userList && Array.isArray(userList)) {
|
||||||
setUsers(userList)
|
setUsers(userList)
|
||||||
if (userList.length > 0) {
|
if (userList.length > 0) {
|
||||||
setUsername(userList[0].name)
|
setUsername(userList[0].name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
console.error("[LoginView] listUsers method not found on API")
|
||||||
|
toast.error("API bridge incomplete")
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
setUsername("web-explorer")
|
setUsername("web-explorer")
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Failed to fetch users:", error)
|
console.error("Failed to fetch users:", error)
|
||||||
|
toast.error("Failed to load identities")
|
||||||
} finally {
|
} finally {
|
||||||
setIsLoadingUsers(false)
|
setIsLoadingUsers(false)
|
||||||
}
|
}
|
||||||
@@ -86,8 +69,14 @@ const LoginView: Component<LoginViewProps> = (props) => {
|
|||||||
try {
|
try {
|
||||||
console.log("[LoginView] isElectronHost:", isElectronHost())
|
console.log("[LoginView] isElectronHost:", isElectronHost())
|
||||||
if (isElectronHost()) {
|
if (isElectronHost()) {
|
||||||
|
const api = getApi()
|
||||||
|
if (!api || !api.listUsers || !api.loginUser) {
|
||||||
|
toast.error("API bridge not ready")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
console.log("[LoginView] Fetching users...")
|
console.log("[LoginView] Fetching users...")
|
||||||
const userList = await safeInvoke("users:list")
|
const userList = await api.listUsers()
|
||||||
if (!userList || !Array.isArray(userList)) {
|
if (!userList || !Array.isArray(userList)) {
|
||||||
toast.error("Bridge failure: try restarting")
|
toast.error("Bridge failure: try restarting")
|
||||||
return
|
return
|
||||||
@@ -102,7 +91,7 @@ const LoginView: Component<LoginViewProps> = (props) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
console.log("[LoginView] Attempting login for:", user.id)
|
console.log("[LoginView] Attempting login for:", user.id)
|
||||||
const result = await safeInvoke("users:login", {
|
const result = await api.loginUser({
|
||||||
id: user.id,
|
id: user.id,
|
||||||
password: password(),
|
password: password(),
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -104,14 +104,11 @@ export async function initializeUserContext(): Promise<void> {
|
|||||||
console.log(`[UserContext] Initializing... host=${isElectronHost()}`)
|
console.log(`[UserContext] Initializing... host=${isElectronHost()}`)
|
||||||
try {
|
try {
|
||||||
if (isElectronHost()) {
|
if (isElectronHost()) {
|
||||||
const api = (window as any).electronAPI || (window as any).electron
|
const api = (window as any).electronAPI
|
||||||
if (api) {
|
if (api && api.getActiveUser) {
|
||||||
console.log(`[UserContext] Requesting active user from host IPC...`)
|
console.log(`[UserContext] Requesting active user via api.getActiveUser()...`)
|
||||||
const invoke = api.invoke || api.ipcRenderer?.invoke || (window as any).ipcRenderer?.invoke
|
const activeUser = await api.getActiveUser()
|
||||||
if (!invoke) throw new Error("No IPC invoke method found")
|
console.log(`[UserContext] getActiveUser result:`, activeUser)
|
||||||
|
|
||||||
const binder = api.invoke ? api : (api.ipcRenderer || (window as any).ipcRenderer)
|
|
||||||
const activeUser = await invoke.call(binder, "users:active")
|
|
||||||
|
|
||||||
if (activeUser?.id) {
|
if (activeUser?.id) {
|
||||||
console.log(`[UserContext] Host has active session: ${activeUser.id}`)
|
console.log(`[UserContext] Host has active session: ${activeUser.id}`)
|
||||||
@@ -121,7 +118,7 @@ export async function initializeUserContext(): Promise<void> {
|
|||||||
setActiveUserId(null)
|
setActiveUserId(null)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
console.warn(`[UserContext] Electron detected but no IPC bridge found. Falling back to web mode.`)
|
console.warn(`[UserContext] electronAPI.getActiveUser not found. Falling back to web mode.`)
|
||||||
await handleWebInit()
|
await handleWebInit()
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user