Compare commits

..

15 commits

Author SHA1 Message Date
4c530edf50
chore: prettier
All checks were successful
CI / Get Changed Files (pull_request) Successful in 8s
CI / Docker backend validation (pull_request) Successful in 34s
CI / Checkstyle Main (pull_request) Successful in 33s
CI / eslint (pull_request) Successful in 49s
CI / oxlint (pull_request) Successful in 27s
CI / prettier (pull_request) Successful in 28s
CI / Docker frontend validation (pull_request) Successful in 1m10s
CI / test-build (pull_request) Successful in 33s
2025-05-07 16:52:05 +02:00
e2124e8b8e
chore: shitty ahh rebase 2025-05-07 16:52:05 +02:00
dcf073abfa
feat(auth): add user refresh functionality in services 2025-05-07 16:52:05 +02:00
b3c4cb4c83
refactor: remove unused parameters and improve formatting 2025-05-07 16:52:05 +02:00
7f90e8cb94
feat(auth): update login and register components design 2025-05-07 16:52:05 +02:00
064cc78402
style: clean up import statements for consistency 2025-05-07 16:52:05 +02:00
8d8af1101b
refactor: clean up unused imports across controllers 2025-05-07 16:51:30 +02:00
a9052466e8
feat(auth): put login and register templates in files 2025-05-07 16:51:30 +02:00
45551551cc
refactor: remove redundant user not found message handling 2025-05-07 16:51:30 +02:00
2c6d5a755f
fix: fix stupid ahh bug where u get logged out when doing fucking anything stupid fucking http interceptor 2025-05-07 16:51:30 +02:00
fb4c7f175a
refactor: simplify user service and update routes 2025-05-07 16:51:29 +02:00
f7e8fd76a6
style: format code and improve readability 2025-05-07 16:51:29 +02:00
c8c82af4b8
feat: implement authentication with JWT and user management 2025-05-07 16:51:29 +02:00
b7279a85ca
Merge branch 'main' into task/CAS-44/lootbox-selection
All checks were successful
CI / Get Changed Files (pull_request) Successful in 13s
CI / Checkstyle Main (pull_request) Has been skipped
CI / Docker frontend validation (pull_request) Successful in 13s
CI / Docker backend validation (pull_request) Successful in 13s
CI / eslint (pull_request) Successful in 27s
CI / oxlint (pull_request) Successful in 26s
CI / prettier (pull_request) Successful in 26s
CI / test-build (pull_request) Successful in 41s
2025-05-07 14:26:50 +00:00
fd079d2460
feat(slots): add slot machine component with styling and logic
All checks were successful
CI / Get Changed Files (pull_request) Successful in 9s
CI / Checkstyle Main (pull_request) Has been skipped
CI / Docker backend validation (pull_request) Successful in 9s
CI / oxlint (pull_request) Successful in 24s
CI / Docker frontend validation (pull_request) Successful in 39s
CI / eslint (pull_request) Successful in 30s
CI / prettier (pull_request) Successful in 29s
CI / test-build (pull_request) Successful in 1m0s
2025-05-07 16:25:43 +02:00
3 changed files with 33 additions and 12 deletions

View file

@ -1,4 +1,11 @@
import { ChangeDetectionStrategy, Component, EventEmitter, inject, Input, Output } from '@angular/core';
import {
ChangeDetectionStrategy,
Component,
EventEmitter,
inject,
Input,
Output,
} from '@angular/core';
import { TransactionService } from '@service/transaction.service';
import { Observable } from 'rxjs';
import { AsyncPipe, CurrencyPipe, DatePipe, NgIf } from '@angular/common';

View file

@ -18,21 +18,24 @@ export class AuthService {
private authUrl = `${environment.apiUrl}/auth`;
private userUrl = `${environment.apiUrl}/users`;
userSubject: BehaviorSubject<User | null>;
private currentUserSubject: BehaviorSubject<User | null>;
public currentUser: Observable<User | null>;
constructor(
private http: HttpClient,
private router: Router
) {
this.userSubject = new BehaviorSubject<User | null>(this.getUserFromStorage());
this.currentUserSubject = new BehaviorSubject<User | null>(this.getUserFromStorage());
this.currentUser = this.currentUserSubject.asObservable();
// Check if token exists and load user data
if (this.getToken()) {
this.loadCurrentUser();
}
}
public get currentUserValue(): User | null {
return this.userSubject.value;
return this.currentUserSubject.value;
}
login(loginRequest: LoginRequest): Observable<AuthResponse> {
@ -51,7 +54,7 @@ export class AuthService {
logout(): void {
localStorage.removeItem(TOKEN_KEY);
localStorage.removeItem(USER_KEY);
this.userSubject.next(null);
this.currentUserSubject.next(null);
this.router.navigate(['/']);
}
@ -80,7 +83,7 @@ export class AuthService {
private setUser(user: User): void {
localStorage.setItem(USER_KEY, JSON.stringify(user));
this.userSubject.next(user);
this.currentUserSubject.next(user);
}
private getUserFromStorage(): User | null {

View file

@ -10,6 +10,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',
@ -23,19 +24,29 @@ export class NavbarComponent implements OnInit, OnDestroy {
private authService: AuthService = inject(AuthService);
isLoggedIn = this.authService.isLoggedIn();
private authSubscription!: Subscription;
private userSubscription: Subscription | undefined;
private authSubscription: Subscription | undefined;
public balance = signal(0);
private userService = inject(UserService);
ngOnInit() {
this.authSubscription = this.authService.userSubject.subscribe({
next: (user) => {
this.balance.set(user?.balance ?? 0);
},
// 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);
});
this.userService.refreshCurrentUser();
}
ngOnDestroy() {
this.authSubscription.unsubscribe();
if (this.userSubscription) {
this.userSubscription.unsubscribe();
}
if (this.authSubscription) {
this.authSubscription.unsubscribe();
}
}
logout() {