diff --git a/backend/chat-service/app.ts b/backend/chat-service/app.ts index a9cfe719..d8b9c78f 100644 --- a/backend/chat-service/app.ts +++ b/backend/chat-service/app.ts @@ -54,12 +54,12 @@ io.on("connection", async (socket: Socket) => { } const accessToken = getCookie("accessToken"); // if your token is called jwt. - console.log("Access Token: " + getCookie("accessToken")) + console.log("Access Token: " + getCookie("accessToken")); if (accessToken) { try { await authenticateAccessToken(accessToken); - + // Middleware ends here // Listen for room joining. socket.on("join-room", async (roomId: string, username?: string) => { @@ -71,19 +71,18 @@ io.on("connection", async (socket: Socket) => { // Broadcast to all connected users that this user has joined the room io.to(roomId).emit("joined-room", username); }); - } catch (error) { console.log(error); console.log("Not authorized, access token failed"); // next(new Error("Not authorized, access token failed")); socket.emit("error", { errorMsg: "Not authorized, access token failed" }); - socket.disconnect() + socket.disconnect(); } } else { console.log("Not authorized, no access token"); // next(new Error("Not authorized, no access token")); socket.emit("error", { errorMsg: "Not authorized, no access token" }); - socket.disconnect() + socket.disconnect(); } // Listen for chat messages. diff --git a/backend/collaboration-service/app.ts b/backend/collaboration-service/app.ts index d0b4b3bf..4174ff82 100644 --- a/backend/collaboration-service/app.ts +++ b/backend/collaboration-service/app.ts @@ -97,8 +97,6 @@ interface UsersAgreedEnd { const usersAgreedEnd: UsersAgreedEnd = {}; - - // Handle other collaboration features. io.on("connection", async (socket) => { console.log("New connection:", socket.id); @@ -135,26 +133,26 @@ io.on("connection", async (socket) => { // Send the initial language to this user. socket.emit("initial-language", initialLanguage); const initialQuestionId = roomCurrentQuestion[roomId]; - if (initialQuestionId) socket.emit("set-first-question", initialQuestionId); + if (initialQuestionId) + socket.emit("set-first-question", initialQuestionId); // Attach user's username and roomId to this connection socket.data.username = username; socket.data.roomId = roomId; // Broadcast to all connected users that this user has joined the room io.to(roomId).emit("user-join", username); }); - } catch (error) { console.log(error); console.log("Not authorized, access token failed"); // next(new Error("Not authorized, access token failed")); socket.emit("error", { errorMsg: "Not authorized, access token failed" }); - socket.disconnect() + socket.disconnect(); } } else { console.log("Not authorized, no access token"); // next(new Error("Not authorized, no access token")); socket.emit("error", { errorMsg: "Not authorized, no access token" }); - socket.disconnect() + socket.disconnect(); } socket.on("user-agreed-next", async (roomId, userId) => { diff --git a/backend/matching-service/src/app.ts b/backend/matching-service/src/app.ts index 1c8d50a2..f98e6b9b 100644 --- a/backend/matching-service/src/app.ts +++ b/backend/matching-service/src/app.ts @@ -47,7 +47,7 @@ io.on("connection", async (socket: Socket) => { } const accessToken = getCookie("accessToken"); // if your token is called jwt. - console.log(getCookie("accessToken")) + console.log(getCookie("accessToken")); if (accessToken) { try { @@ -58,13 +58,13 @@ io.on("connection", async (socket: Socket) => { console.log("Not authorized, access token failed"); // next(new Error("Not authorized, access token failed")); socket.emit("error", { errorMsg: "Not authorized, access token failed" }); - socket.disconnect() + socket.disconnect(); } } else { console.log("Not authorized, no access token"); // next(new Error("Not authorized, no access token")); socket.emit("error", { errorMsg: "Not authorized, no access token" }); - socket.disconnect() + socket.disconnect(); } }); diff --git a/backend/user-service/src/controllers/authController.ts b/backend/user-service/src/controllers/authController.ts index 64bf5af5..e6702e44 100644 --- a/backend/user-service/src/controllers/authController.ts +++ b/backend/user-service/src/controllers/authController.ts @@ -159,7 +159,7 @@ export async function logOut(req: Request, res: Response) { const refreshToken = req.cookies["refreshToken"]; // If JWT token is stored in a cookie if (refreshToken) { const decoded = (await authenticateRefreshToken( - refreshToken + refreshToken, )) as JwtPayload; const userId = decoded.user.id; // user ID is used for identification if (userId) { @@ -173,7 +173,7 @@ export async function logOut(req: Request, res: Response) { // This means access token has expired console.log("Cannot remove login refresh token from server: " + error); console.log( - "You might have removed it somehow. Suggested that you login again to remove old refreshToken from server." + "You might have removed it somehow. Suggested that you login again to remove old refreshToken from server.", ); console.log("Proceeding with rest of log out procedure..."); } @@ -212,7 +212,7 @@ export const oAuthAuthenticate: RequestHandler[] = [ "Access-Control-Allow-Origin": "*", Accept: "application/json", }, - } + }, ); const resp = await response.text(); @@ -226,8 +226,8 @@ export const oAuthAuthenticate: RequestHandler[] = [ const githubUser = await user_resp.json(); const githubUserId = githubUser["id"] as number; const user = await prisma.user.findFirst({ - where: { - githubId: githubUserId + where: { + githubId: githubUserId, }, include: { languages: true, @@ -560,7 +560,7 @@ export async function updateAccessToken(req: Request, res: Response) { } else { try { const decoded = (await authenticateRefreshToken( - refreshToken + refreshToken, )) as JwtPayload; const userWithoutPassword = decoded.user; @@ -632,7 +632,7 @@ export const updateUserProfile: RequestHandler[] = [ const accessToken = req.cookies["accessToken"]; // If JWT token is stored in a cookie const decoded = (await authenticateAccessToken( - accessToken + accessToken, )) as JwtPayload; const userId = decoded.user.id; // user ID is used for identification @@ -682,8 +682,8 @@ export const updateUserProfile: RequestHandler[] = [ // UPDATING BOTH TOKENS // Fetch the latest user data from the database const user = await prisma.user.findFirst({ - where: { - id: userId + where: { + id: userId, }, include: { languages: true, @@ -691,7 +691,11 @@ export const updateUserProfile: RequestHandler[] = [ }); if (!user) { - return res.status(401).json({ message: "Had issues retrieving user while updating tokens" }); + return res + .status(401) + .json({ + message: "Had issues retrieving user while updating tokens", + }); } // @@ -703,7 +707,8 @@ export const updateUserProfile: RequestHandler[] = [ username: user.username, } as UserWithoutPassword; const updatedAccessToken = await generateAccessToken(userWithoutPassword); - const updatedRefreshToken = await generateRefreshToken(userWithoutPassword); + const updatedRefreshToken = + await generateRefreshToken(userWithoutPassword); await prisma.user.update({ where: { id: userId }, @@ -725,7 +730,6 @@ export const updateUserProfile: RequestHandler[] = [ message: "User profile updated successfully", user: updatedUser, }); - } catch (error) { if ( error instanceof Prisma.PrismaClientKnownRequestError && diff --git a/backend/user-service/src/middleware/authMiddleware.ts b/backend/user-service/src/middleware/authMiddleware.ts index fbf1757e..1af46d67 100644 --- a/backend/user-service/src/middleware/authMiddleware.ts +++ b/backend/user-service/src/middleware/authMiddleware.ts @@ -29,7 +29,7 @@ export interface JwtPayload { export async function verifyAccessToken( req: Request, res: Response, - next: NextFunction + next: NextFunction, ) { const accessToken = req.cookies["accessToken"]; // If JWT token is stored in a cookie @@ -52,7 +52,7 @@ export async function verifyAccessToken( export async function protectAdmin( req: Request, res: Response, - next: NextFunction + next: NextFunction, ) { const accessToken = req.cookies["accessToken"]; // If JWT token is stored in a cookie const decoded = (await authenticateAccessToken(accessToken)) as JwtPayload; diff --git a/docker-compose.yml b/docker-compose.yml index f06310a1..05587244 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -81,7 +81,12 @@ services: ports: - "5672:5672" - "15672:15672" - command: ["bash", "-c", "chmod 400 /var/lib/rabbitmq/.erlang.cookie; rabbitmq-server"] + command: + [ + "bash", + "-c", + "chmod 400 /var/lib/rabbitmq/.erlang.cookie; rabbitmq-server", + ] healthcheck: test: rabbitmq-diagnostics check_port_connectivity interval: 1s diff --git a/frontend/src/components/chat/ChatBox.tsx b/frontend/src/components/chat/ChatBox.tsx index a1b885cf..0e268a4b 100644 --- a/frontend/src/components/chat/ChatBox.tsx +++ b/frontend/src/components/chat/ChatBox.tsx @@ -54,7 +54,6 @@ const ChatBox: React.FC = () => { // Join the room useEffect(() => { - const setInitial = (roomId: string, currentUser: User): void => { // Emit a request to join the room socket.current?.emit('join-room', roomId, currentUser); diff --git a/frontend/src/pages/matching/Matching.tsx b/frontend/src/pages/matching/Matching.tsx index 6adc455e..b41d1488 100644 --- a/frontend/src/pages/matching/Matching.tsx +++ b/frontend/src/pages/matching/Matching.tsx @@ -24,7 +24,6 @@ const Matching: React.FC = () => { const [matchingState, setMatchingState] = useState(MatchingStateEnum.NO_REQUEST); useEffect(() => { - const newSocket = io(process.env.REACT_APP_MATCHING_SERVICE_BACKEND_URL as string, { path: process.env.REACT_APP_MATCHING_SERVICE_PATH ?? '/socket.io/', transports: ['websocket'],