aboutsummaryrefslogtreecommitdiffhomepage
path: root/frontend/app/routes/golf.$gameId.watch.tsx
diff options
context:
space:
mode:
Diffstat (limited to 'frontend/app/routes/golf.$gameId.watch.tsx')
-rw-r--r--frontend/app/routes/golf.$gameId.watch.tsx30
1 files changed, 17 insertions, 13 deletions
diff --git a/frontend/app/routes/golf.$gameId.watch.tsx b/frontend/app/routes/golf.$gameId.watch.tsx
index 07e8c9e..556eb03 100644
--- a/frontend/app/routes/golf.$gameId.watch.tsx
+++ b/frontend/app/routes/golf.$gameId.watch.tsx
@@ -1,7 +1,7 @@
import { Provider as JotaiProvider, createStore } from "jotai";
import { useMemo } from "react";
import type { LoaderFunctionArgs, MetaFunction } from "react-router";
-import { useLoaderData } from "react-router";
+import { redirect, useLoaderData } from "react-router";
import { ensureUserLoggedIn } from "../.server/auth";
import { ApiClientContext, createApiClient } from "../api/client";
import GolfWatchApp from "../components/GolfWatchApp";
@@ -20,18 +20,22 @@ export async function loader({ params, request }: LoaderFunctionArgs) {
const gameId = Number(params.gameId);
- const [{ game }, { ranking }, { states: gameStates }] = await Promise.all([
- await apiClient.getGame(gameId),
- await apiClient.getGameWatchRanking(gameId),
- await apiClient.getGameWatchLatestStates(gameId),
- ]);
-
- return {
- apiToken: token,
- game,
- ranking,
- gameStates,
- };
+ try {
+ const [{ game }, { ranking }, { states: gameStates }] = await Promise.all([
+ await apiClient.getGame(gameId),
+ await apiClient.getGameWatchRanking(gameId),
+ await apiClient.getGameWatchLatestStates(gameId),
+ ]);
+
+ return {
+ apiToken: token,
+ game,
+ ranking,
+ gameStates,
+ };
+ } catch {
+ throw redirect("/dashboard");
+ }
}
export default function GolfWatch() {