feat: implement authentication with JWT and user management

This commit is contained in:
Constantin Simonis 2025-05-07 13:42:04 +02:00
commit 35d8fbaea0
No known key found for this signature in database
GPG key ID: 3878FF77C24AF4D2
42 changed files with 989 additions and 397 deletions

View file

@ -51,7 +51,7 @@ export default class BlackjackComponent implements OnInit {
debtAmount = signal(0);
ngOnInit(): void {
this.userService.currentUser$.subscribe((user) => {
this.userService.getCurrentUser().subscribe((user) => {
if (user) {
this.balance.set(user.balance);
}
@ -83,7 +83,7 @@ export default class BlackjackComponent implements OnInit {
if (isGameOver) {
console.log('Game is over, state:', game.state);
this.userService.refreshCurrentUser();
// this.userService.refreshCurrentUser();
timer(1500).subscribe(() => {
this.showGameResult.set(true);
console.log('Game result dialog shown after delay');
@ -97,7 +97,7 @@ export default class BlackjackComponent implements OnInit {
this.blackjackService.startGame(bet).subscribe({
next: (game) => {
this.updateGameState(game);
this.userService.refreshCurrentUser();
// this.userService.refreshCurrentUser();
this.isActionInProgress.set(false);
},
error: (error) => {
@ -116,7 +116,7 @@ export default class BlackjackComponent implements OnInit {
next: (game) => {
this.updateGameState(game);
if (game.state !== 'IN_PROGRESS') {
this.userService.refreshCurrentUser();
// this.userService.refreshCurrentUser();
}
this.isActionInProgress.set(false);
},
@ -141,7 +141,7 @@ export default class BlackjackComponent implements OnInit {
this.blackjackService.stand(this.currentGameId()!).subscribe({
next: (game) => {
this.updateGameState(game);
this.userService.refreshCurrentUser();
// this.userService.refreshCurrentUser();
this.isActionInProgress.set(false);
},
error: (error) => {
@ -184,7 +184,7 @@ export default class BlackjackComponent implements OnInit {
onCloseGameResult(): void {
console.log('Closing game result dialog');
this.showGameResult.set(false);
this.userService.refreshCurrentUser();
// this.userService.refreshCurrentUser();
}
onCloseDebtDialog(): void {
@ -195,11 +195,11 @@ export default class BlackjackComponent implements OnInit {
if (error instanceof HttpErrorResponse) {
if (error.status === 400 && error.error?.error === 'Invalid state') {
this.gameInProgress.set(false);
this.userService.refreshCurrentUser();
// this.userService.refreshCurrentUser();
} else if (error.status === 500) {
console.log('Server error occurred. The game may have been updated in another session.');
this.gameInProgress.set(false);
this.userService.refreshCurrentUser();
// this.userService.refreshCurrentUser();
if (this.currentGameId()) {
this.refreshGameState(this.currentGameId()!);
}