diff --git a/frontend/src/components/Sidebar/AppSidebar.tsx b/frontend/src/components/Sidebar/AppSidebar.tsx index a85a79d..a741a1b 100644 --- a/frontend/src/components/Sidebar/AppSidebar.tsx +++ b/frontend/src/components/Sidebar/AppSidebar.tsx @@ -70,9 +70,11 @@ export function AppSidebar() { // depend on where the caret happens to be. useShortcuts({ "mod+k": () => setSearchOpen((open) => !open) }, ["mod+k"]) + // Secrets and Admin are a superuser's: anyone else would open them onto a + // permission error. const withAdmin = currentUser?.is_superuser ? [...baseItems, { icon: Users, title: "Admin", path: "/admin" }] - : baseItems + : baseItems.filter((item) => item.path !== "/secrets") // Reached through a portal, the way out is back to the instances list — // and the session belongs to the portal, so logging out is its business. diff --git a/frontend/src/routes/_layout/secrets.tsx b/frontend/src/routes/_layout/secrets.tsx index b462dbd..b244d98 100644 --- a/frontend/src/routes/_layout/secrets.tsx +++ b/frontend/src/routes/_layout/secrets.tsx @@ -1,9 +1,9 @@ import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query" -import { createFileRoute } from "@tanstack/react-router" +import { createFileRoute, redirect } from "@tanstack/react-router" import { KeyRound, Plus, Trash2 } from "lucide-react" import { useState } from "react" -import { SecretsService } from "@/client" +import { SecretsService, UsersService } from "@/client" import { Button } from "@/components/ui/button" import { Dialog, @@ -19,6 +19,15 @@ import { handleError } from "@/utils" export const Route = createFileRoute("/_layout/secrets")({ component: Secrets, + // `GET /secrets/` is a superuser's, as Admin is. + beforeLoad: async () => { + const user = await UsersService.readUserMe() + if (!user.is_superuser) { + throw redirect({ + to: "/", + }) + } + }, head: () => ({ meta: [ {