From 4af93cae1ca54ad7c9bc7eb4b56c010f55c4c72d Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 20 Feb 2026 17:53:55 +0000 Subject: feat: allow viewing/spectating games without login Make watch, ranking, game list, and tournament endpoints accessible without authentication. Unauthenticated users can browse games and spectate from the index page, while play/submit/preview still require login. https://claude.ai/code/session_019j9tNcnLsLz15e1qtbmeqe --- backend/api/handler.go | 4 +-- backend/api/handler_wrapper.go | 35 ++++------------------ backend/gen/api/handler_wrapper_gen.go | 15 +++++++++- frontend/app/App.tsx | 14 ++------- frontend/app/pages/DashboardPage.tsx | 54 +++++++++++++++++++++------------- frontend/app/pages/GolfWatchPage.tsx | 18 ++++++++---- frontend/app/pages/IndexPage.tsx | 3 +- 7 files changed, 72 insertions(+), 71 deletions(-) diff --git a/backend/api/handler.go b/backend/api/handler.go index 57ae973..dcebfa1 100644 --- a/backend/api/handler.go +++ b/backend/api/handler.go @@ -218,7 +218,7 @@ func (h *Handler) GetGame(ctx context.Context, request GetGameRequestObject, use } return nil, echo.NewHTTPError(http.StatusInternalServerError, err.Error()) } - if !row.IsPublic && !user.IsAdmin { + if !row.IsPublic && (user == nil || !user.IsAdmin) { return GetGame404JSONResponse{ Message: "Game not found", }, nil @@ -318,7 +318,7 @@ func (h *Handler) GetGameWatchLatestStates(ctx context.Context, request GetGameW Status: status, } - if row.UserID == user.UserID && !user.IsAdmin { + if user != nil && row.UserID == user.UserID && !user.IsAdmin { return GetGameWatchLatestStates403JSONResponse{ Message: "You are one of the main players of this game", }, nil diff --git a/backend/api/handler_wrapper.go b/backend/api/handler_wrapper.go index 48a0eef..1c8bc83 100644 --- a/backend/api/handler_wrapper.go +++ b/backend/api/handler_wrapper.go @@ -28,12 +28,7 @@ func NewHandler(queries db.Querier, txm db.TxManager, hub GameHubInterface, auth } func (h *HandlerWrapper) GetGame(ctx context.Context, request GetGameRequestObject) (GetGameResponseObject, error) { - user, ok := GetUserFromContext(ctx) - if !ok { - return GetGame401JSONResponse{ - Message: "Unauthorized", - }, nil - } + user, _ := GetUserFromContext(ctx) return h.impl.GetGame(ctx, request, user) } @@ -58,32 +53,17 @@ func (h *HandlerWrapper) GetGamePlaySubmissions(ctx context.Context, request Get } func (h *HandlerWrapper) GetGameWatchLatestStates(ctx context.Context, request GetGameWatchLatestStatesRequestObject) (GetGameWatchLatestStatesResponseObject, error) { - user, ok := GetUserFromContext(ctx) - if !ok { - return GetGameWatchLatestStates401JSONResponse{ - Message: "Unauthorized", - }, nil - } + user, _ := GetUserFromContext(ctx) return h.impl.GetGameWatchLatestStates(ctx, request, user) } func (h *HandlerWrapper) GetGameWatchRanking(ctx context.Context, request GetGameWatchRankingRequestObject) (GetGameWatchRankingResponseObject, error) { - user, ok := GetUserFromContext(ctx) - if !ok { - return GetGameWatchRanking401JSONResponse{ - Message: "Unauthorized", - }, nil - } + user, _ := GetUserFromContext(ctx) return h.impl.GetGameWatchRanking(ctx, request, user) } func (h *HandlerWrapper) GetGames(ctx context.Context, request GetGamesRequestObject) (GetGamesResponseObject, error) { - user, ok := GetUserFromContext(ctx) - if !ok { - return GetGames401JSONResponse{ - Message: "Unauthorized", - }, nil - } + user, _ := GetUserFromContext(ctx) return h.impl.GetGames(ctx, request, user) } @@ -98,12 +78,7 @@ func (h *HandlerWrapper) GetMe(ctx context.Context, request GetMeRequestObject) } func (h *HandlerWrapper) GetTournament(ctx context.Context, request GetTournamentRequestObject) (GetTournamentResponseObject, error) { - user, ok := GetUserFromContext(ctx) - if !ok { - return GetTournament401JSONResponse{ - Message: "Unauthorized", - }, nil - } + user, _ := GetUserFromContext(ctx) return h.impl.GetTournament(ctx, request, user) } diff --git a/backend/gen/api/handler_wrapper_gen.go b/backend/gen/api/handler_wrapper_gen.go index e3e56c1..982e191 100644 --- a/backend/gen/api/handler_wrapper_gen.go +++ b/backend/gen/api/handler_wrapper_gen.go @@ -61,16 +61,26 @@ func main() { } slices.Sort(methods) + loginOptionalMethods := map[string]bool{ + "GetGames": true, + "GetGame": true, + "GetGameWatchLatestStates": true, + "GetGameWatchRanking": true, + "GetTournament": true, + } + type TemplateParameter struct { Name string RequiresLogin bool + LoginOptional bool RequiresAdminRole bool } templateParameters := make([]TemplateParameter, len(methods)) for i, method := range methods { templateParameters[i] = TemplateParameter{ Name: method, - RequiresLogin: method != "PostLogin", + RequiresLogin: method != "PostLogin" && !loginOptionalMethods[method], + LoginOptional: loginOptionalMethods[method], RequiresAdminRole: strings.Contains(method, "Admin"), } } @@ -144,6 +154,9 @@ func NewHandler(queries db.Querier, txm db.TxManager, hub GameHubInterface, auth } {{ end -}} return h.impl.{{ .Name }}(ctx, request, user) + {{ else if .LoginOptional -}} + user, _ := GetUserFromContext(ctx) + return h.impl.{{ .Name }}(ctx, request, user) {{ else -}} return h.impl.{{ .Name }}(ctx, request) {{ end -}} diff --git a/frontend/app/App.tsx b/frontend/app/App.tsx index 3f1333a..be608e4 100644 --- a/frontend/app/App.tsx +++ b/frontend/app/App.tsx @@ -26,9 +26,7 @@ export default function App() { - - - + {(params) => ( @@ -52,17 +50,11 @@ export default function App() { )} - {(params) => ( - - - - )} + {(params) => } {(params) => ( - - - + )} diff --git a/frontend/app/pages/DashboardPage.tsx b/frontend/app/pages/DashboardPage.tsx index 00db3f0..92c0f04 100644 --- a/frontend/app/pages/DashboardPage.tsx +++ b/frontend/app/pages/DashboardPage.tsx @@ -14,7 +14,7 @@ type Game = components["schemas"]["Game"]; export default function DashboardPage() { usePageTitle(`Dashboard | ${APP_NAME}`); - const { user, logout } = useAuth(); + const { user, isLoggedIn, isLoading: authLoading, logout } = useAuth(); const [, navigate] = useLocation(); const [games, setGames] = useState([]); @@ -33,7 +33,7 @@ export default function DashboardPage() { navigate("/"); } - if (loading) { + if (loading || authLoading) { return (

Loading...

@@ -43,18 +43,24 @@ export default function DashboardPage() { return (
- {user?.icon_path && ( + {isLoggedIn && user?.icon_path && ( )} -

{user?.display_name}

+ {isLoggedIn ? ( +

+ {user?.display_name} +

+ ) : ( +

試合一覧

+ )}
{games.length === 0 ? ( -

エントリーできる試合はありません

+

試合はありません

) : (
    {games.map((game) => ( @@ -68,20 +74,24 @@ export default function DashboardPage() {
- {game.started_at == null && ( + {isLoggedIn && game.started_at == null && ( 問題を見る )} - - 対戦 - + {isLoggedIn && ( + + 対戦 + + )} 観戦 - - 提出履歴 - + {isLoggedIn && ( + + 提出履歴 + + )}
))} @@ -89,14 +99,18 @@ export default function DashboardPage() { )}
- - {user?.is_admin && ( + {isLoggedIn ? ( + + ) : ( + ログイン + )} + {isLoggedIn && user?.is_admin && ( (null); const [ranking, setRanking] = useState([]); const [gameStates, setGameStates] = useState<{ [key: string]: LatestGameState; }>({}); const [loading, setLoading] = useState(true); + const [error, setError] = useState(false); const gameIdNum = Number(gameId); @@ -41,16 +39,16 @@ export default function GolfWatchPage({ gameId }: { gameId: string }) { setRanking(ranking); setGameStates(states); }) - .catch(() => navigate("/dashboard")) + .catch(() => setError(true)) .finally(() => setLoading(false)); - }, [gameIdNum, navigate]); + }, [gameIdNum]); const store = useMemo(() => { if (!game) return null; return createStore(); }, [game]); - if (loading || !game || !store) { + if (loading) { return (

Loading...

@@ -58,6 +56,14 @@ export default function GolfWatchPage({ gameId }: { gameId: string }) { ); } + if (error || !game || !store) { + return ( +
+

試合が見つかりませんでした

+
+ ); + } + return ( diff --git a/frontend/app/pages/IndexPage.tsx b/frontend/app/pages/IndexPage.tsx index 120720a..03e135b 100644 --- a/frontend/app/pages/IndexPage.tsx +++ b/frontend/app/pages/IndexPage.tsx @@ -31,7 +31,8 @@ export default function IndexPage() {

-
+
+ 観戦する ログイン
-- cgit v1.3.1 From d39a86dd2cdb3f12bcb43713345fbba57a95ad58 Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 21 Feb 2026 00:29:23 +0000 Subject: fix: resolve biome formatting error in App.tsx tournament route https://claude.ai/code/session_019j9tNcnLsLz15e1qtbmeqe --- frontend/app/App.tsx | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/frontend/app/App.tsx b/frontend/app/App.tsx index be608e4..31adc28 100644 --- a/frontend/app/App.tsx +++ b/frontend/app/App.tsx @@ -53,9 +53,7 @@ export default function App() { {(params) => } - {(params) => ( - - )} + {(params) => }
-- cgit v1.3.1 From 277c9726f0f39d1db83624a8b62a77ac19c2ac0a Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 21 Feb 2026 00:33:09 +0000 Subject: fix: resolve gofmt formatting in handler_wrapper_gen.go https://claude.ai/code/session_019j9tNcnLsLz15e1qtbmeqe --- backend/gen/api/handler_wrapper_gen.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/backend/gen/api/handler_wrapper_gen.go b/backend/gen/api/handler_wrapper_gen.go index 982e191..88f55c6 100644 --- a/backend/gen/api/handler_wrapper_gen.go +++ b/backend/gen/api/handler_wrapper_gen.go @@ -62,11 +62,11 @@ func main() { slices.Sort(methods) loginOptionalMethods := map[string]bool{ - "GetGames": true, - "GetGame": true, - "GetGameWatchLatestStates": true, - "GetGameWatchRanking": true, - "GetTournament": true, + "GetGames": true, + "GetGame": true, + "GetGameWatchLatestStates": true, + "GetGameWatchRanking": true, + "GetTournament": true, } type TemplateParameter struct { -- cgit v1.3.1