加固后台管理安全

This commit is contained in:
yml2213
2026-06-11 07:23:00 +08:00
parent 5255b21141
commit 88b1df64e7
41 changed files with 1276 additions and 293 deletions
+9 -1
View File
@@ -14,7 +14,7 @@ const userKeys = {
const adminKeys = {
accessToken: 'admin_access_token',
refreshToken: 'admin_refresh_token',
profile: ['admin_id', 'admin_username'],
profile: ['admin_id', 'admin_username', 'admin_support_status', 'admin_password_must_change'],
}
function keysFor(scope: AuthScope) {
@@ -22,15 +22,23 @@ function keysFor(scope: AuthScope) {
}
export function getAccessToken(scope: AuthScope) {
if (scope === 'admin') return ''
return localStorage.getItem(keysFor(scope).accessToken) || ''
}
export function getRefreshToken(scope: AuthScope) {
if (scope === 'admin') return ''
return localStorage.getItem(keysFor(scope).refreshToken) || ''
}
export function setAuthTokens(scope: AuthScope, tokens: AuthTokenPair) {
const keys = keysFor(scope)
if (scope === 'admin') {
localStorage.removeItem(keys.accessToken)
localStorage.removeItem(keys.refreshToken)
notifyAuthStorageChanged(scope)
return
}
localStorage.setItem(keys.accessToken, tokens.access_token)
localStorage.setItem(keys.refreshToken, tokens.refresh_token)
notifyAuthStorageChanged(scope)