feat(auth): add user refresh functionality in services
Some checks failed
CI / Get Changed Files (pull_request) Successful in 9s
CI / Docker backend validation (pull_request) Successful in 10s
CI / Docker frontend validation (pull_request) Failing after 36s
CI / oxlint (pull_request) Failing after 27s
CI / eslint (pull_request) Failing after 33s
CI / Checkstyle Main (pull_request) Successful in 46s
CI / prettier (pull_request) Failing after 23s
CI / test-build (pull_request) Failing after 31s

This commit is contained in:
Constantin Simonis 2025-05-07 15:35:33 +02:00
commit 84250969aa
No known key found for this signature in database
GPG key ID: 3878FF77C24AF4D2
3 changed files with 24 additions and 18 deletions

View file

@ -66,6 +66,17 @@ export class AuthService {
return localStorage.getItem(TOKEN_KEY);
}
public loadCurrentUser(): void {
this.http.get<User>(`${this.userUrl}/me`).subscribe({
next: (user) => {
this.setUser(user);
},
error: () => {
this.logout();
},
});
}
private setToken(token: string): void {
localStorage.setItem(TOKEN_KEY, token);
}
@ -80,17 +91,6 @@ export class AuthService {
return user ? JSON.parse(user) : null;
}
private loadCurrentUser(): void {
this.http.get<User>(`${this.userUrl}/me`).subscribe({
next: (user) => {
this.setUser(user);
},
error: () => {
this.logout();
},
});
}
getUser(): User | null {
return this.currentUserValue;
}