加固后台管理安全
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user