Skip to content

How quickly should removing an admin role take effect?

1 min read · main part only; folded sections are optional

After this you can answer: How quickly should removing an admin role take effect?

The context resolves only the session’s user identifier. The admin middleware then distinguishes missing authentication, a deleted user and a non-admin role. Those become unauthorized or forbidden responses as appropriate. A database error remains an error; it is not permission to continue.

The make-admin service revokes sessions before changing the role and again afterwards. That narrows a concurrent-login window and requires fresh login after a successful promotion. It is still two systems with no shared transaction: a failure after the database update can leave a changed role even though the overall command failed.

For a high-risk demotion, I would discuss checking authorization again inside the protected write transaction or introducing a durable security version. Those are proposed hardening choices, not guarantees the current code provides.

Why not put the role in the cookie?
A trusted signed claim can still be stale. Without expiry or revocation checks, removing privileges would not affect an already issued token.
What if the account was deleted?
The admin lookup returns no role, and the middleware rejects the request as unauthorized. A session record alone does not prove that an admin account still exists.
Does checking on every request remove every race?
No. A request can pass the check before a concurrent demotion commits and perform its write later. The required guarantee must say whether that window is acceptable.

Read Rbac, then inspect the api-app piece →.

apps/api/src/trpc/init.ts → isAdmin

Read this book online: https://book.theversehub.in/