chore(deps): upgrade Angular 19 → 20
- ng update @angular/core@20 @angular/cli@20 @angular/material@20 @angular-eslint@20 @angular/google-maps@20 - Remove ng-chartist (abandoned, incompatible with Angular 20): replace <x-chartist> with <app-bars-chart> in dropzones-bar and jumps-by-month - Migrate all constructor injection to inject() function (ng generate @angular/core:inject, 67 files) - TypeScript 5.5 → 5.9.3 - DOCUMENT import moved from @angular/common to @angular/core (automatic migration) - tsconfig moduleResolution updated to "bundler"
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { Injectable, OnDestroy } from '@angular/core';
|
||||
import { HttpClient } from "@angular/common/http";
|
||||
import { Injectable, OnDestroy, inject } from '@angular/core';
|
||||
import { HttpClient } from '@angular/common/http';
|
||||
import { Observable, BehaviorSubject, ReplaySubject, Subscription } from 'rxjs';
|
||||
import { distinctUntilChanged, take, tap } from 'rxjs/operators';
|
||||
|
||||
@@ -8,6 +8,9 @@ import { JwtService } from '@services';
|
||||
|
||||
@Injectable({ providedIn: 'root' })
|
||||
export class UserService implements OnDestroy {
|
||||
private readonly http = inject(HttpClient);
|
||||
private readonly jwtService = inject(JwtService);
|
||||
|
||||
private _subcriptions: Array<Subscription> = new Array<Subscription>();
|
||||
private _user: Subscription = new Subscription();
|
||||
private currentUserSubject = new BehaviorSubject<User>({} as User);
|
||||
@@ -16,12 +19,7 @@ export class UserService implements OnDestroy {
|
||||
private isAuthenticatedSubject = new ReplaySubject<boolean>(1);
|
||||
public isAuthenticated = this.isAuthenticatedSubject.asObservable();
|
||||
|
||||
|
||||
private _apiDomain = '/cms';
|
||||
constructor(
|
||||
private readonly http: HttpClient,
|
||||
private readonly jwtService: JwtService
|
||||
) { }
|
||||
|
||||
ngOnDestroy() {
|
||||
this._subcriptions.forEach((subscription: Subscription) => subscription.unsubscribe());
|
||||
@@ -32,10 +30,12 @@ export class UserService implements OnDestroy {
|
||||
populate() {
|
||||
// If JWT detected, attempt to get & store user's info
|
||||
if (this.jwtService.getToken()) {
|
||||
const user$: Observable<{ user: User }> = this.http.get<{ user: User }>(`${this._apiDomain}/user`).pipe(take(1));
|
||||
const user$: Observable<{ user: User }> = this.http
|
||||
.get<{ user: User }>(`${this._apiDomain}/user`)
|
||||
.pipe(take(1));
|
||||
this._user = user$.subscribe({
|
||||
next: (data) => this.setAuth(data.user),
|
||||
error: () => this.purgeAuth()
|
||||
error: () => this.purgeAuth(),
|
||||
});
|
||||
this._subcriptions.push(this._user);
|
||||
} else {
|
||||
@@ -62,9 +62,11 @@ export class UserService implements OnDestroy {
|
||||
this.isAuthenticatedSubject.next(false);
|
||||
}
|
||||
|
||||
attemptAuth(type: string, credentials?: { email: string; password: string; }): Observable<{ user: User }> {
|
||||
const route = (type === 'login') ? '/login' : '';
|
||||
const user$: Observable<{ user: User }> = this.http.post<{ user: User }>(`${this._apiDomain}/user${route}`, { user: credentials });
|
||||
attemptAuth(type: string, credentials?: { email: string; password: string }): Observable<{ user: User }> {
|
||||
const route = type === 'login' ? '/login' : '';
|
||||
const user$: Observable<{ user: User }> = this.http.post<{ user: User }>(`${this._apiDomain}/user${route}`, {
|
||||
user: credentials,
|
||||
});
|
||||
/*return user$.pipe(map(
|
||||
(data: any) => {
|
||||
this.setAuth(data.user);
|
||||
@@ -79,7 +81,7 @@ export class UserService implements OnDestroy {
|
||||
}
|
||||
|
||||
canAdministrate(): boolean {
|
||||
return (this.currentUserSubject.value.role == 'Admin') ? true : false;
|
||||
return this.currentUserSubject.value.role == 'Admin' ? true : false;
|
||||
}
|
||||
|
||||
// Update the user on the server (email, pass, etc)
|
||||
@@ -90,5 +92,4 @@ export class UserService implements OnDestroy {
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user