Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Update handler for critical error while parsing game token #158

Merged
merged 1 commit into from
Dec 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading