Skip to content

Commit

Permalink
client: Store user id in authenticated user details.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
kuv2707 committed Jun 25, 2024
1 parent 4191a64 commit 63150df
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions frontend/src/contexts/AuthContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { useLocation, useNavigate } from 'react-router-dom';

export type User = {
name: string;
id: string;
};

export type AuthContextProps = {
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
},
Expand Down

0 comments on commit 63150df

Please sign in to comment.