This commit is contained in:
薇薇安 2026-01-21 14:17:21 +08:00
parent 9bc73b63a3
commit 2d9adddb91

View File

@ -8,7 +8,7 @@ import Recommendations from './components/Recommendations'
import LogMonitor from './components/LogMonitor'
import AccountSelector from './components/AccountSelector'
import Login from './components/Login'
import { api, clearAuthToken } from './services/api'
import { api, clearAuthToken, setCurrentAccountId, getCurrentAccountId } from './services/api'
import './App.css'
function App() {
@ -19,6 +19,25 @@ function App() {
try {
const u = await api.me()
setMe(u)
//
// account_id == user.id
try {
if ((u?.role || '') !== 'admin') {
const list = await api.getAccounts()
const accounts = Array.isArray(list) ? list : []
const uid = parseInt(String(u?.id || ''), 10)
const match = accounts.find((a) => parseInt(String(a?.id || ''), 10) === uid)
const target = match?.id || accounts[0]?.id
if (target) {
const cur = getCurrentAccountId()
const next = parseInt(String(target), 10)
if (Number.isFinite(next) && next > 0 && cur !== next) setCurrentAccountId(next)
}
}
} catch (e) {
// ignore
}
} catch (e) {
setMe(null)
} finally {