feat(frontend): implement P0 optimization baseline
This commit is contained in:
@@ -33,11 +33,11 @@ export function getAdminRole() {
|
||||
return role
|
||||
}
|
||||
|
||||
return 'operator'
|
||||
return 'support'
|
||||
}
|
||||
|
||||
export function hasAdminRole(role: 'admin' | 'operator' | 'support') {
|
||||
if (!getAdminToken()) {
|
||||
if (!hasAdminSession()) {
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -74,5 +74,26 @@ export function clearAdminSession() {
|
||||
}
|
||||
|
||||
export function hasAdminSession() {
|
||||
return Boolean(getAdminToken())
|
||||
const token = getAdminToken()
|
||||
const expiresAt = getAdminTokenExpiresAt()
|
||||
|
||||
if (!token) {
|
||||
return false
|
||||
}
|
||||
|
||||
if (isExpired(expiresAt)) {
|
||||
clearAdminSession()
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
function isExpired(expiresAt: string) {
|
||||
if (!expiresAt) {
|
||||
return false
|
||||
}
|
||||
|
||||
const expiresAtMs = Date.parse(expiresAt)
|
||||
return Number.isFinite(expiresAtMs) && expiresAtMs <= Date.now()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user