forked from code100x/chess
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request code100x#115 from N4r35h/main
Add basic Guest play support
- Loading branch information
Showing
16 changed files
with
182 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const COOKIE_MAX_AGE = 24 * 60 * 60 * 1000; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { Player } from "../screens/Game" | ||
|
||
interface PlayerTitleProps { | ||
player: Player | undefined | ||
isSelf?: boolean | ||
} | ||
|
||
export const PlayerTitle = ({player, isSelf}: PlayerTitleProps) => { | ||
return ( | ||
<div className="flex gap-1"> | ||
{player && player.id.startsWith("guest") && | ||
<p className="text-gray-500"> | ||
[Guest] | ||
</p> | ||
} | ||
<p>{player && player.name}</p> | ||
{isSelf && | ||
<p className="text-gray-500">(You)</p> | ||
} | ||
</div> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,24 @@ | ||
export const UserAvatar = ({ name }: { name: string }) => { | ||
return <div className="text-white">{name}</div>; | ||
import { useUser } from '@repo/store/useUser'; | ||
import { Metadata, Player } from '../screens/Game'; | ||
|
||
interface UserAvatarProps { | ||
gameMetadata: Metadata | null; | ||
self?: boolean; | ||
} | ||
|
||
export const UserAvatar = ({ gameMetadata, self }: UserAvatarProps) => { | ||
const user = useUser(); | ||
let player: Player; | ||
if (gameMetadata?.blackPlayer.id === user.id) { | ||
player = self ? gameMetadata.blackPlayer : gameMetadata.whitePlayer; | ||
} else { | ||
player = self ? gameMetadata?.whitePlayer! : gameMetadata?.blackPlayer!; | ||
} | ||
|
||
return ( | ||
<div className="text-white flex gap-2 "> | ||
<p>{player?.name}</p> | ||
{player?.isGuest && <p className="text-gray-500">[Guest]</p>} | ||
</div> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,17 @@ | ||
import jwt from 'jsonwebtoken'; | ||
import { User } from '../SocketManager'; | ||
import { Player } from '../Game'; | ||
import { WebSocket } from 'ws'; | ||
|
||
const JWT_SECRET = process.env.JWT_SECRET || 'your_secret_key'; | ||
|
||
export const extractUserId = (token: string) => { | ||
const decoded = jwt.verify(token, JWT_SECRET) as { userId: string }; | ||
return decoded.userId; | ||
export interface userJwtClaims { | ||
userId: string; | ||
name: string; | ||
isGuest?: boolean; | ||
} | ||
|
||
export const extractAuthUser = (token: string, ws: WebSocket): User => { | ||
const decoded = jwt.verify(token, JWT_SECRET) as userJwtClaims; | ||
return new User(ws, decoded); | ||
}; |
Oops, something went wrong.