fix: harden startup flow and auth re-entry

This commit is contained in:
Misaka
2026-03-21 11:02:17 +08:00
parent ed65312fff
commit 9a1f5a483e
10 changed files with 86 additions and 38 deletions

View File

@@ -43,9 +43,10 @@ export class SessionManager {
* @returns True if login successful, false otherwise
*/
public async login(username: string, password: string): Promise<boolean> {
let dao: InstanceType<(typeof import('./bip-users-dao'))['BIPUsersDAO']> | null = null
try {
const { BIPUsersDAO } = await import('./bip-users-dao')
const dao = new BIPUsersDAO()
dao = new BIPUsersDAO()
const userInfo = await dao.authenticate(username, password)
if (userInfo) {
@@ -60,6 +61,12 @@ export class SessionManager {
} catch (error) {
console.error('[SessionManager] Login error:', error)
return false
} finally {
if (dao) {
await dao.disconnect().catch((error) => {
console.error('[SessionManager] Login disconnect error:', error)
})
}
}
}
@@ -68,10 +75,11 @@ export class SessionManager {
* @returns True if login successful, false otherwise
*/
public async loginByComputerName(): Promise<boolean> {
let dao: InstanceType<(typeof import('./bip-users-dao'))['BIPUsersDAO']> | null = null
try {
const { BIPUsersDAO } = await import('./bip-users-dao')
const { hostname } = await import('os')
const dao = new BIPUsersDAO()
dao = new BIPUsersDAO()
const computerName = hostname()
const userInfo = await dao.authenticateByComputerName(computerName)
@@ -87,6 +95,12 @@ export class SessionManager {
} catch (error) {
console.error('[SessionManager] Silent login error:', error)
return false
} finally {
if (dao) {
await dao.disconnect().catch((error) => {
console.error('[SessionManager] Silent login disconnect error:', error)
})
}
}
}
@@ -174,13 +188,20 @@ export class SessionManager {
* Get all users from database (for Admin user selection)
*/
public async getAllUsers(): Promise<UserInfo[]> {
let dao: InstanceType<(typeof import('./bip-users-dao'))['BIPUsersDAO']> | null = null
try {
const { BIPUsersDAO } = await import('./bip-users-dao')
const dao = new BIPUsersDAO()
dao = new BIPUsersDAO()
return await dao.getAllUsers()
} catch (error) {
console.error('[SessionManager] Get all users error:', error)
return []
} finally {
if (dao) {
await dao.disconnect().catch((error) => {
console.error('[SessionManager] Get all users disconnect error:', error)
})
}
}
}
}