plugins: introduced clearer key isAdmin in frontend state and session
Massimo Melina committed
May 8, 2026 at 11:29 UTC
c7c404c1fc02242dc02bac4f2842425655ca7bee
4 files changed
+6
-3
admin/src/LoginRequired.ts
+1
-1
@@ -68,7 +68,7 @@ async function login(username: string, password: string, extra?: object) {
68
: err?.name === 'AbortError' ? "Server didn't respond"
69
: (err?.message || "Unknown error")
70
})
71
- if (!res.adminUrl)
71
+ if (!res.isAdmin)
72
throw "This account has no Admin access"
73
74
// login was successful, update state
frontend/src/state.ts
+1
@@ -22,6 +22,7 @@ export const state = proxy<typeof FRONTEND_OPTIONS & {
22
showFilter: boolean,
23
selected: { [uri:string]: true }, // by using an object instead of an array, Entry components are not rendered when others get selected
24
remoteSearch: { search?: string, searchComment?: string, wild?: string } | undefined,
25
+ isAdmin?: boolean,
26
adminUrl?: string,
27
loginRequired?: boolean, // force user to login before proceeding
28
messageOnly?: string, // no gui, just show this message
shared/index.ts
+1
-1
@@ -146,7 +146,7 @@ export function makeSessionRefresher(state: any) {
146
147
function refreshSession(response?: any) {
148
clearTimeout(timeout)
149
- const keys = ['username', 'adminUrl', 'canChangePassword', 'accountExp', 'expandedUsername', 'requireChangePassword']
149
+ const keys = ['username', 'isAdmin', 'adminUrl', 'canChangePassword', 'accountExp', 'expandedUsername', 'requireChangePassword']
150
response ??= objFromKeys(keys, () => undefined)
151
const { exp } = response
152
getHFS().session = Object.assign(state, _.pick(response, keys))
src/api.auth.ts
+3
-1
@@ -21,10 +21,12 @@ const keepSessionAlive = defineConfig('keep_session_alive', true)
21
22
const refresh_session: ApiHandler = async ({}, ctx) => {
23
const username = getCurrentUsername(ctx)
24
+ const isAdmin = ctxAdminAccess(ctx) || undefined
25
return !ctx.session ? new ApiError(HTTP_SERVER_ERROR) : {
26
username,
27
expandedUsername: Array.from(expandUsername(username)),
27
- adminUrl: ctxAdminAccess(ctx) ? ctx.state.revProxyPath + ADMIN_URI : undefined,
28
+ isAdmin,
29
+ adminUrl: isAdmin && ctx.state.revProxyPath + ADMIN_URI,
30
canChangePassword: accountCanChangePassword(ctx.state.account),
31
requireChangePassword: ctx.state.account?.require_password_change,
32
exp: username && keepSessionAlive.get() ? new Date(Date.now() + sessionDuration.compiled()) : undefined,