diff options
Diffstat (limited to 'frontend')
| -rw-r--r-- | frontend/app/routes/admin.dashboard.tsx | 28 | ||||
| -rw-r--r-- | frontend/app/routes/dashboard.tsx | 4 |
2 files changed, 32 insertions, 0 deletions
diff --git a/frontend/app/routes/admin.dashboard.tsx b/frontend/app/routes/admin.dashboard.tsx new file mode 100644 index 0000000..d5f3809 --- /dev/null +++ b/frontend/app/routes/admin.dashboard.tsx @@ -0,0 +1,28 @@ +import type { LoaderFunctionArgs, MetaFunction } from "@remix-run/node"; +import { Link } from "@remix-run/react"; +import { isAuthenticated } from "../.server/auth"; + +export const meta: MetaFunction = () => { + return [{ title: "[Admin] Dashboard | iOSDC 2024 Albatross.swift" }]; +}; + +export async function loader({ request }: LoaderFunctionArgs) { + const { user } = await isAuthenticated(request, { + failureRedirect: "/login", + }); + if (!user.is_admin) { + throw new Error("Unauthorized"); + } + return null; +} + +export default function AdminDashboard() { + return ( + <div> + <h1>[Admin] Dashboard</h1> + <p> + <Link to="/admin/users">Users</Link> + </p> + </div> + ); +} diff --git a/frontend/app/routes/dashboard.tsx b/frontend/app/routes/dashboard.tsx index 9afee86..badf8c4 100644 --- a/frontend/app/routes/dashboard.tsx +++ b/frontend/app/routes/dashboard.tsx @@ -1,4 +1,5 @@ import type { LoaderFunctionArgs, MetaFunction } from "@remix-run/node"; +import { redirect } from "@remix-run/node"; import { Link, useLoaderData, Form } from "@remix-run/react"; import { isAuthenticated } from "../.server/auth"; import { apiClient } from "../.server/api/client"; @@ -11,6 +12,9 @@ export async function loader({ request }: LoaderFunctionArgs) { const { user, token } = await isAuthenticated(request, { failureRedirect: "/login", }); + if (user.is_admin) { + return redirect("/admin/dashboard"); + } const { data, error } = await apiClient.GET("/games", { params: { query: { |
