Gate admin nav links by per-section permission
Gate admin nav links by per-section permission
#15 in tonybierman/dx-blog — merged 2026-05-30
Problem
As an editor, the admin sidebar showed Dashboard, Users, and Analytics links that, when opened, errored with "error running server function: You don't have permission for this action." The sidebar gated on any admin token, so it rendered every section regardless of which capabilities the user actually held.
Changes
- Per-link gating (
pages/admin/mod.rs): each sidebar link is wrapped in arium's inlinePermissionGate, keyed to the exact token its page's server fns require (ANALYTICS_READ,POSTS_WRITE,MEDIA_UPLOAD,COMMENTS_MODERATE,USERS_MANAGE,SETTINGS_WRITE). The link simply doesn't render when the token is absent — no redirect. admin_landing()helper: returns the first sidebar section a user can open, in nav order. Single source of truth so the header link and sidebar gates can't drift.- Header "Admin" link (
layouts.rs): now targetsadmin_landing(...)instead of a hardcoded Dashboard, so an editor lands on Posts while a full admin still lands on Dashboard. - Direct-nav hardening (
pages/admin/dashboard.rs): the analytics-backed Dashboard/Analytics pages bounce a user withoutANALYTICS_READto their first accessible section instead of rendering the raw permission error (covers bookmarks / typed/admin).
The server fns remain the real authorization boundary; this just paints the UI to match what each user can do, using arium's membership-gate pattern rather than hand-rolled checks.
Testing
cargo fmtcargo check --no-default-features --features server,sqlitecargo check --no-default-features --features web --target wasm32-unknown-unknown
🤖 Generated with Claude Code
Last updated 2026-05-30
Links to this note
Credits
Merged pull requests, newest first.