fix: 应用启动即绑定用户数据库(修复刷新/登录后数据库未就绪的白屏)
This commit is contained in:
@@ -67,8 +67,13 @@ export function clearCloudCreds(): void {
|
||||
localStorage.removeItem(CREDS_KEY)
|
||||
}
|
||||
|
||||
let openedFor: string | null = null
|
||||
|
||||
export function openUserDatabase(userId: string): void {
|
||||
if (openedFor === userId && db) return
|
||||
if (db) unbindDatabase()
|
||||
bindDatabase(new WorklogDB(LEGACY_DB_NAME + '_' + userId))
|
||||
openedFor = userId
|
||||
}
|
||||
|
||||
export async function createUser(username: string, password: string, migrateLegacy: boolean): Promise<Session> {
|
||||
@@ -110,6 +115,7 @@ export async function login(username: string, password: string): Promise<Session
|
||||
export async function logoutUser(): Promise<void> {
|
||||
lockVault()
|
||||
unbindDatabase()
|
||||
openedFor = null
|
||||
clearSession()
|
||||
clearCloudCreds()
|
||||
}
|
||||
@@ -132,6 +138,7 @@ export async function deleteCurrentUser(): Promise<void> {
|
||||
if (!s) throw new Error('未登录')
|
||||
lockVault()
|
||||
unbindDatabase()
|
||||
openedFor = null
|
||||
await Dexie.delete(LEGACY_DB_NAME + '_' + s.userId)
|
||||
await registry.user.delete(s.userId)
|
||||
clearSession()
|
||||
|
||||
Reference in New Issue
Block a user