Dough Git

clove/pkviewer

web/src/routes/manage/+layout.server.ts

back to web/src/routes/manage

/* web/src/routes/manage/+layout.server.ts */
import { redirect } from "@sveltejs/kit";
import type { LayoutServerLoad } from "./$types";
import { isAuthenticated, isPlatformAdmin } from "$lib/server/api.ts";

/**
 * Every /manage route requires a session, checked here so no page has to
 * remember to. A courtesy: the API refuses unauthenticated calls regardless.
 */
export const load: LayoutServerLoad = async () => {
  if (!(await isAuthenticated())) redirect(303, "/login?return_to=/manage");

  // Presentation only: /admin re-checks the grant, so hiding the link keeps nobody out
  return { admin: await isPlatformAdmin() };
};