This commit is contained in:
2026-08-26 20:50:58 +08:00
parent 258f5414d1
commit 88b52cff40
14 changed files with 488 additions and 90 deletions
+5 -4
View File
@@ -34,8 +34,7 @@ function persistSession() {
currentUser: session.currentUser,
token: session.token,
refreshToken: session.refreshToken,
tenantId: session.tenantId,
apiBase: session.apiBase
tenantId: session.tenantId
})
}
@@ -44,7 +43,9 @@ export function signIn(account, warehouse, options = {}) {
session.token = options.token || account.token || ''
session.refreshToken = options.refreshToken || account.refreshToken || ''
session.tenantId = options.tenantId || account.tenantId || ''
session.apiBase = options.apiBase || account.apiBase || PLATFORM_API_ROOT
// The endpoint belongs to the installed build, not to a persisted login.
// Otherwise changing environments leaves existing devices on the old API.
session.apiBase = PLATFORM_API_ROOT
persistSession()
return session.currentUser
}
@@ -73,7 +74,7 @@ export function restoreSession() {
try {
const claims = decodeAccessToken(saved.token)
if (claims.exp && claims.exp * 1000 <= Date.now()) return false
Object.assign(session, saved, { apiBase: saved.apiBase || PLATFORM_API_ROOT })
Object.assign(session, saved, { apiBase: PLATFORM_API_ROOT })
return true
} catch (_) {
return false