Skip to content

Commit

Permalink
!fix: build client
Browse files Browse the repository at this point in the history
  • Loading branch information
jagnani73 committed Sep 2, 2024
1 parent 9f8af50 commit fac0c61
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 36 deletions.
8 changes: 6 additions & 2 deletions packages/backend/services/ws.service.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
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";

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,
Expand All @@ -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);
Expand Down
8 changes: 4 additions & 4 deletions packages/common/index.ts
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -175,7 +176,7 @@ export default function Game({ tier }: Props) {
const socketRef = useRef<Socket>(
getSocketManager().socket(`/${RockPaperScissors.slug}`, {
auth: {
// token,
token: player_token,
},
})
);
Expand Down
57 changes: 28 additions & 29 deletions packages/frontend/src/app/profile/page.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"use client";

import { useEffect, useState } from "react";
import { useState } from "react";
import {
ProfileHero,
WalletDetails,
Expand All @@ -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();
Expand All @@ -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 (
<main className="text-neutral-100 flex flex-col gap-y-4 pb-10">
Expand Down

0 comments on commit fac0c61

Please sign in to comment.