Skip to content

Commit

Permalink
fix: update handler for critical error while parsing game token
Browse files Browse the repository at this point in the history
  • Loading branch information
vcwild committed Dec 6, 2023
1 parent e40d01e commit eef0a60
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
11 changes: 7 additions & 4 deletions backend/src/game/game.gateway.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,16 @@ export class GameGateway implements OnGatewayConnection, OnGatewayDisconnect {

handleConnection(client: Socket) {
// Get user from cookie coming from client
const user = client.handshake.auth.token;

// Decode user from JWT
const decodedUser = this.jwtService.decode(user).sub;

const user = client.handshake.auth.token;
const decodedUser = this.jwtService.decode(user)?.sub;
if (!decodedUser) {
this.logger.error('Token invalid or expired');
client.disconnect();
return;
}
this.pool.set(decodedUser, client);

this.logger.log(`Client ${decodedUser} connected`);
}

Expand Down
4 changes: 2 additions & 2 deletions frontend/src/contexts/AuthContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import nookies from "nookies";
import React, { createContext, useEffect, useState } from "react";
import { api } from "@/services/apiClient";
import { redirect } from "next/navigation";
import { User } from "@/types/user";
import { useGetMe } from "@/services/queries/user/getMe";

Expand Down Expand Up @@ -32,7 +31,8 @@ export const AuthContext = createContext<AuthContextType>(
export function signOut() {
nookies.destroy(null, "accesssToken");
nookies.destroy(null, "refreshToken");
redirect("/login");
api.defaults.headers["Authorization"] = "";
window.location.replace("/");
}

export const AuthProvider = ({ children }: AuthProviderProps) => {
Expand Down

0 comments on commit eef0a60

Please sign in to comment.