From fac0c615c3a0e7badf482ed8ab23ea89df1c4a82 Mon Sep 17 00:00:00 2001 From: Yashvardhan Jagnani Date: Mon, 2 Sep 2024 20:58:30 +0530 Subject: [PATCH] !fix: build client --- packages/backend/services/ws.service.ts | 8 ++- packages/common/index.ts | 8 +-- .../rock-paper-scissors/components/Game.tsx | 3 +- packages/frontend/src/app/profile/page.tsx | 57 +++++++++---------- 4 files changed, 40 insertions(+), 36 deletions(-) diff --git a/packages/backend/services/ws.service.ts b/packages/backend/services/ws.service.ts index 20e5a5e..aec413c 100644 --- a/packages/backend/services/ws.service.ts +++ b/packages/backend/services/ws.service.ts @@ -1,5 +1,6 @@ import { ConnectFourRoutes } from "../microservices/connect-four/connect-four.routes"; import { RockPaperScissorsRoutes } from "../microservices/rock-paper-scissors/rock-paper-scissors.routes"; +import { validateJwt } from "../middlewares/ws"; import { GAME_NAMESPACES } from "common"; import { Server } from "node:http"; import { type Namespace, type Socket, Server as WSServer } from "socket.io"; @@ -7,7 +8,10 @@ import { type Namespace, type Socket, Server as WSServer } from "socket.io"; export class WSService { private static ioConnection: WSServer; private static socketRoutes: { - [namespace in GAME_NAMESPACES]: (socket: Socket, io: Namespace) => void; + [namespace in (typeof GAME_NAMESPACES)[keyof typeof GAME_NAMESPACES]]: ( + socket: Socket, + io: Namespace, + ) => void; } = { [GAME_NAMESPACES.ROCK_PAPER_SCISSORS]: RockPaperScissorsRoutes, [GAME_NAMESPACES.CONNECT_FOUR]: ConnectFourRoutes, @@ -31,7 +35,7 @@ export class WSService { scopedIO.use((socket, next) => { try { const token = socket.handshake.auth.token; - // validateJwt(token); + validateJwt(token); next(); } catch (error: Error | any) { next(error); diff --git a/packages/common/index.ts b/packages/common/index.ts index 9a4da9a..2797246 100644 --- a/packages/common/index.ts +++ b/packages/common/index.ts @@ -1,10 +1,10 @@ import * as ConnectFour from "./connect-four"; import * as RockPaperScissors from "./rock-paper-scissors"; -export enum GAME_NAMESPACES { - ROCK_PAPER_SCISSORS = RockPaperScissors.slug, - CONNECT_FOUR = ConnectFour.slug, -} +export const GAME_NAMESPACES = { + ROCK_PAPER_SCISSORS: RockPaperScissors.slug, + CONNECT_FOUR: ConnectFour.slug, +} as const; export enum TIERS_IDS { ALPHA = "5f534987-4ca5-4b27-8597-835fc9512f85", diff --git a/packages/frontend/src/app/games/rock-paper-scissors/components/Game.tsx b/packages/frontend/src/app/games/rock-paper-scissors/components/Game.tsx index a7dd997..526200d 100644 --- a/packages/frontend/src/app/games/rock-paper-scissors/components/Game.tsx +++ b/packages/frontend/src/app/games/rock-paper-scissors/components/Game.tsx @@ -54,6 +54,7 @@ export default function Game({ tier }: Props) { const { user } = useWeb3AuthContext(); const player_user_id = user!.data.player_id; + const player_token = user!.token; const reducer = ( gameState: GameState, @@ -175,7 +176,7 @@ export default function Game({ tier }: Props) { const socketRef = useRef( getSocketManager().socket(`/${RockPaperScissors.slug}`, { auth: { - // token, + token: player_token, }, }) ); diff --git a/packages/frontend/src/app/profile/page.tsx b/packages/frontend/src/app/profile/page.tsx index a7e82c4..8ed4c3c 100644 --- a/packages/frontend/src/app/profile/page.tsx +++ b/packages/frontend/src/app/profile/page.tsx @@ -1,6 +1,6 @@ "use client"; -import { useEffect, useState } from "react"; +import { useState } from "react"; import { ProfileHero, WalletDetails, @@ -10,9 +10,8 @@ import { import { CustomChainConfig } from "@web3auth/base"; import { CHAINS } from "@/utils/constants/chain-config.constant"; import { web3auth } from "@/utils/service/web3auth.service"; -import { MappedPlayedGame, ResponseWithData } from "@/utils/types"; +import { MappedPlayedGame } from "@/utils/types"; import { useWeb3AuthContext } from "@/utils/context/web3auth.context"; -import { API_REST_BASE_URL } from "@/utils/constants/api.constant"; const Profile: React.FC = () => { const { user } = useWeb3AuthContext(); @@ -27,35 +26,35 @@ const Profile: React.FC = () => { )! ); - useEffect(() => { - (async () => { - try { - if (!user) { - return; - } + // useEffect(() => { + // (async () => { + // try { + // if (!user) { + // return; + // } - setLoading(true); + // setLoading(true); - const gamesRes = await fetch( - `${API_REST_BASE_URL}/played-games/${user.data.player_id}`, - { - cache: "no-cache", - } - ); - const gamesResponse = (await gamesRes.json()) as ResponseWithData< - MappedPlayedGame[] - >; + // const gamesRes = await fetch( + // `${API_REST_BASE_URL}/played-games/${user.data.player_id}`, + // { + // cache: "no-cache", + // } + // ); + // const gamesResponse = (await gamesRes.json()) as ResponseWithData< + // MappedPlayedGame[] + // >; - if (gamesResponse.success) { - setPlayedGames(gamesResponse.data); - } - } catch (error) { - console.error(error); - } finally { - setLoading(false); - } - })(); - }, []); + // if (gamesResponse.success) { + // setPlayedGames(gamesResponse.data); + // } + // } catch (error) { + // console.error(error); + // } finally { + // setLoading(false); + // } + // })(); + // }, []); return (