feat: implement authentication with JWT and user management
This commit is contained in:
parent
b7279a85ca
commit
c8c82af4b8
42 changed files with 989 additions and 397 deletions
|
@ -26,10 +26,13 @@ export class NavbarComponent implements OnInit, OnDestroy {
|
|||
|
||||
private userService = inject(UserService);
|
||||
private userSubscription: Subscription | undefined;
|
||||
private authSubscription: Subscription | undefined;
|
||||
public balance = signal(0);
|
||||
|
||||
ngOnInit() {
|
||||
this.userSubscription = this.userService.currentUser$.subscribe((user) => {
|
||||
// Subscribe to auth changes
|
||||
this.authSubscription = this.authService.currentUser.subscribe(user => {
|
||||
this.isLoggedIn = !!user;
|
||||
this.balance.set(user?.balance ?? 0);
|
||||
console.log('Updated navbar balance:', user?.balance);
|
||||
});
|
||||
|
@ -41,13 +44,8 @@ export class NavbarComponent implements OnInit, OnDestroy {
|
|||
if (this.userSubscription) {
|
||||
this.userSubscription.unsubscribe();
|
||||
}
|
||||
}
|
||||
|
||||
login() {
|
||||
try {
|
||||
this.authService.login();
|
||||
} catch (error) {
|
||||
console.error('Login failed:', error);
|
||||
if (this.authSubscription) {
|
||||
this.authSubscription.unsubscribe();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Reference in a new issue