Skip to content

Newly granted Discord admins can open admin pages but cannot use admin actions #15

Description

@YoyoJesus

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)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions