diff options
| author | nsfisis <nsfisis@gmail.com> | 2025-03-21 15:11:30 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2025-03-21 15:40:40 +0900 |
| commit | 432baae1b49343ea780793330149a285a53bbdc7 (patch) | |
| tree | 3dc84e517910fb7e15f172bab5a803a6379a7c32 /frontend/app/routes/golf.$gameId.play.tsx | |
| parent | 589d2355910e8fc63eabecad631b16b3d3d6a492 (diff) | |
| download | phperkaigi-2025-albatross-432baae1b49343ea780793330149a285a53bbdc7.tar.gz phperkaigi-2025-albatross-432baae1b49343ea780793330149a285a53bbdc7.tar.zst phperkaigi-2025-albatross-432baae1b49343ea780793330149a285a53bbdc7.zip | |
wip
Diffstat (limited to 'frontend/app/routes/golf.$gameId.play.tsx')
| -rw-r--r-- | frontend/app/routes/golf.$gameId.play.tsx | 28 |
1 files changed, 16 insertions, 12 deletions
diff --git a/frontend/app/routes/golf.$gameId.play.tsx b/frontend/app/routes/golf.$gameId.play.tsx index 8f41257..d9907aa 100644 --- a/frontend/app/routes/golf.$gameId.play.tsx +++ b/frontend/app/routes/golf.$gameId.play.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 GolfPlayApp from "../components/GolfPlayApp"; @@ -20,17 +20,21 @@ export async function loader({ params, request }: LoaderFunctionArgs) { const gameId = Number(params.gameId); - const [{ game }, { state: gameState }] = await Promise.all([ - apiClient.getGame(gameId), - apiClient.getGamePlayLatestState(gameId), - ]); - - return { - apiToken: token, - game, - player: user, - gameState, - }; + try { + const [{ game }, { state: gameState }] = await Promise.all([ + apiClient.getGame(gameId), + apiClient.getGamePlayLatestState(gameId), + ]); + + return { + apiToken: token, + game, + player: user, + gameState, + }; + } catch { + throw redirect("/dashboard"); + } } export default function GolfPlay() { |
