Skip to content

Commit

Permalink
Force admin/login on admin pages
Browse files Browse the repository at this point in the history
  • Loading branch information
dcramer committed Dec 31, 2023
1 parent f304a2e commit 19b161c
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
9 changes: 9 additions & 0 deletions apps/web/app/routes/admin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,15 @@ import type { MetaFunction } from "@remix-run/node";
import { Outlet } from "@remix-run/react";

import type { SitemapFunction } from "remix-sitemap";
import { redirectToAuth } from "../lib/auth";
import { makeIsomorphicLoader } from "../lib/isomorphicLoader";

export const { loader, clientLoader } = makeIsomorphicLoader(
async ({ request, context: { user } }) => {
if (!user?.admin) return redirectToAuth({ request });
return null;
},
);

export const sitemap: SitemapFunction = () => ({
exclude: true,
Expand Down
7 changes: 7 additions & 0 deletions apps/web/app/routes/admin_.sites_.$siteId_.edit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@ import invariant from "tiny-invariant";
import SiteForm from "../components/admin/siteForm";
import { trpc } from "../lib/trpc";

export const { loader, clientLoader } = makeIsomorphicLoader(
async ({ request, context: { user } }) => {
if (!user?.admin) return redirectToAuth({ request });
return null;
},
);

export const sitemap: SitemapFunction = () => ({
exclude: true,
});
Expand Down
7 changes: 7 additions & 0 deletions apps/web/app/routes/admin_.sites_.add_._index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ import type { SitemapFunction } from "remix-sitemap";
import SiteForm from "../components/admin/siteForm";
import { trpc } from "../lib/trpc";

export const { loader, clientLoader } = makeIsomorphicLoader(
async ({ request, context: { user } }) => {
if (!user?.admin) return redirectToAuth({ request });
return null;
},
);

export const sitemap: SitemapFunction = () => ({
exclude: true,
});
Expand Down

0 comments on commit 19b161c

Please sign in to comment.