blob: bda563f950ca134ae0c923a8884c467694deb2c1 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
import type { LoaderFunctionArgs } from "@remix-run/node";
import { isAuthenticated } from "../.server/auth";
import { apiClient } from "../.server/api/client";
import { useLoaderData } from "@remix-run/react";
import GolfPlayApp from "../components/GolfPlayApp";
export async function loader({ params, request }: LoaderFunctionArgs) {
const { token } = await isAuthenticated(request, {
failureRedirect: "/login",
});
const { data, error } = await apiClient.GET("/games/{game_id}", {
params: {
path: {
game_id: Number(params.gameId),
},
header: {
Authorization: `Bearer ${token}`,
},
},
});
if (error) {
throw new Error(error.message);
}
return {
game: data,
};
}
export default function GolfPlay() {
const { game } = useLoaderData<typeof loader>();
return <GolfPlayApp game={game} />;
}
|