From 63150df43a3cfb7adc9d4851a5a55612b7a85715 Mon Sep 17 00:00:00 2001 From: Kislay Date: Tue, 25 Jun 2024 19:04:51 +0530 Subject: [PATCH] client: Store user id in authenticated user details. Earlier we only stored the user name. We need to store the id to be able to track whether it is the current player's turn, show the Start Game button etc. --- frontend/src/contexts/AuthContext.tsx | 3 +++ 1 file changed, 3 insertions(+) diff --git a/frontend/src/contexts/AuthContext.tsx b/frontend/src/contexts/AuthContext.tsx index 1952cdf..dcbbb7c 100644 --- a/frontend/src/contexts/AuthContext.tsx +++ b/frontend/src/contexts/AuthContext.tsx @@ -12,6 +12,7 @@ import { useLocation, useNavigate } from 'react-router-dom'; export type User = { name: string; + id: string; }; export type AuthContextProps = { @@ -81,6 +82,7 @@ export function AuthProvider({ children }: { children: ReactElement }) { // so the jwt was valid setUser({ name: data.user.username, + id: data.user._id, }); authWith(localToken!, data.user._id); } @@ -118,6 +120,7 @@ export function AuthProvider({ children }: { children: ReactElement }) { console.log(data); setUser({ name: data.user.username, + id: data.user._id, }); authWith(data.token, data.user._id); },