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"; export const meta: MetaFunction = () => { return [{ title: "Dashboard | iOSDC 2024 Albatross.swift" }]; }; 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: { player_id: user.user_id, }, header: { Authorization: `Bearer ${token}`, }, }, }); if (error) { throw new Error(error.message); } return { user, games: data.games, }; } export default function Dashboard() { const { user, games } = useLoaderData()!; return (

{user.username}{" "} {user.is_admin && admin}

User

  • Name: {user.display_name}

Games

    {games.map((game) => (
  • {game.display_name}{" "} {game.state === "closed" || game.state === "finished" ? ( Entry ) : ( Entry )}
  • ))}
); }