Skip to content
17 linesCodeBlameRaw
1import { data } from "react-router";
2
3import type { Route } from "./+types/spend-pill";
4import { managesBilling, requireUser, roleIn } from "../../lib/session.server";
5import { loadPill } from "../../lib/spend.server";
6
7/**
8 * The top bar's spend pill, read after the page draws (components/spend.tsx
9 * `SpendPill`): the viewer's month, and the workspace's for owners and
10 * billing managers.
11 */
12export async function loader({ params, context, request }: Route.LoaderArgs) {
13 const viewer = requireUser(context, request);
14 const slug = params.owner.toLowerCase();
15 if (!roleIn(viewer, slug)) throw data(null, { status: 404 });
16 return data(await loadPill(viewer, slug, managesBilling(viewer, slug)), { headers: { "Cache-Control": "private, no-store" } });
17}