Newly granted Discord admins can open admin pages but cannot use admin actions
- Dominant language
- TypeScript
- Stars
- 0
- Forks
- 0
- PR merge metrics
- No merged PRs in 30d
Description
## Problem
The request hook refreshes the Discord role and authorizes `/admin` using the value returned by `refreshDiscordRole`, but it does not update `event.locals.user.role`. Every admin action separately checks the stale `locals.user` object with `isAdmin(locals.user)`.
A user whose stored role changes from `user` to `admin` during the hook therefore passes the page guard but receives 403 from actions such as tile creation, verification, and activity purge until they start a new session.
## Reproduction
1. Sign in while the stored role is `user`.
2. Grant the user the configured Discord admin role.
3. Request an admin page. The hook refreshes the database role and allows the page.
4. Submit an admin action in that same session. The action sees `locals.user.role === 'user'` and rejects it.
## Suggested fix
After a successful role refresh, assign the refreshed role to `event.locals.user.role`, or have the actions use an authoritative role check that reads or refreshes the current database role.
## Affected code
- `src/hooks.server.ts`
- `src/lib/server/admin.ts`
- all admin actions that call `isAdmin(locals.user)`
Contributor guide
No contributing guide indexed for this repository
Research direction
Read src/hooks.server.ts and src/lib/server/admin.ts first, then trace the admin actions that call isAdmin(locals.user). Reproduce the session flow described in the issue and verify that a newly granted admin can complete an action in the same session while a non-admin still receives the authorization failure.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- authorization, backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Active
- Clarity
- Clearly specified
- Newbie friendliness
- 72/100