diff --git a/frontend/src/app/service/user.service.ts b/frontend/src/app/service/user.service.ts index aa2a687..7530f79 100644 --- a/frontend/src/app/service/user.service.ts +++ b/frontend/src/app/service/user.service.ts @@ -2,22 +2,20 @@ import { inject, Injectable } from '@angular/core'; import { HttpClient } from '@angular/common/http'; import { BehaviorSubject, catchError, EMPTY, Observable, tap } from 'rxjs'; import { User } from '../model/User'; -import { environment } from '@environments/environment'; import { AuthService } from '@service/auth.service'; @Injectable({ providedIn: 'root', }) export class UserService { - private apiUrl = `${environment.apiUrl}/users`; - - private currentUserSubject = new BehaviorSubject(null); + public currentUserSubject = new BehaviorSubject(null); + public currentUser$ = this.currentUserSubject.asObservable(); private http: HttpClient = inject(HttpClient); - private authService: AuthService = inject(AuthService); + private authService = inject(AuthService); public getCurrentUser(): Observable { - return this.http.get('/backend/user').pipe( + return this.http.get('/backend/users/me').pipe( catchError(() => EMPTY), tap((user) => this.currentUserSubject.next(user)) ); @@ -25,6 +23,7 @@ export class UserService { public refreshCurrentUser(): void { this.getCurrentUser().subscribe(); + this.authService.loadCurrentUser(); } public updateLocalBalance(amount: number): void { @@ -37,8 +36,4 @@ export class UserService { this.currentUserSubject.next(updatedUser); } } - - public refreshCurrentUser(): void { - this.authService.loadCurrentUser(); - } } diff --git a/frontend/src/app/shared/components/navbar/navbar.component.ts b/frontend/src/app/shared/components/navbar/navbar.component.ts index bdc941c..c57a8a5 100644 --- a/frontend/src/app/shared/components/navbar/navbar.component.ts +++ b/frontend/src/app/shared/components/navbar/navbar.component.ts @@ -3,6 +3,7 @@ import { RouterModule } from '@angular/router'; import { AuthService } from '@service/auth.service'; import { Subscription } from 'rxjs'; import { AnimatedNumberComponent } from '@blackjack/components/animated-number/animated-number.component'; +import { UserService } from '@service/user.service'; @Component({ selector: 'app-navbar', @@ -19,6 +20,7 @@ export class NavbarComponent implements OnInit, OnDestroy { private userSubscription: Subscription | undefined; private authSubscription: Subscription | undefined; public balance = signal(0); + private userService = inject(UserService); ngOnInit() { // Subscribe to auth changes