CodeIssuesDiscussionsWikiPull RequestsProjectsCommitsActionsReleasesContributorsPulse● GatesSecuritySettingsDeploymentsPipelineInsightsAgents✨ Explain✨ Ask AI✨ Workspace✨ Spec✨ Tests▓ Debt Map✨ NL Search🏛 Archaeology
Blame · Line-by-line history
admin.ts
Each line is annotated with the commit that last touched it. Click any SHA to jump to that commit and see the surrounding change.
| a4f3e24 | 1 | /** |
| 2 | * Admin middleware — blocks non-admin users. | |
| 3 | * Must be used AFTER softAuth or requireAuth. | |
| 4 | */ | |
| 5 | ||
| 6 | import { createMiddleware } from "hono/factory"; | |
| 7 | import type { AuthEnv } from "./auth"; | |
| 8 | ||
| 9 | export const requireAdmin = createMiddleware<AuthEnv>(async (c, next) => { | |
| 10 | const user = c.get("user"); | |
| 11 | ||
| 12 | if (!user) { | |
| 13 | return c.redirect(`/login?redirect=${encodeURIComponent(c.req.path)}`); | |
| 14 | } | |
| 15 | ||
| 16 | if (!user.isAdmin) { | |
| 17 | return c.html( | |
| 18 | `<html><body style="background:#0d1117;color:#e6edf3;font-family:sans-serif;display:flex;justify-content:center;align-items:center;height:100vh"> | |
| 19 | <div style="text-align:center"> | |
| 20 | <h1>403</h1> | |
| 21 | <p>Admin access required.</p> | |
| 22 | <a href="/" style="color:#58a6ff">Go home</a> | |
| 23 | </div> | |
| 24 | </body></html>`, | |
| 25 | 403 | |
| 26 | ); | |
| 27 | } | |
| 28 | ||
| 29 | return next(); | |
| 30 | }); |