Add email verification functionality, including backend support, email handling, and user interface integration.
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import {Injectable, signal} from '@angular/core';
|
||||
import {LoginService} from '@api';
|
||||
import {BehaviorSubject, Observable, throwError} from 'rxjs';
|
||||
import {Observable, throwError} from 'rxjs';
|
||||
import {catchError, tap} from 'rxjs/operators';
|
||||
import {MatSnackBar} from '@angular/material/snack-bar';
|
||||
import {JwtHelperService} from '@auth0/angular-jwt';
|
||||
@@ -10,11 +10,10 @@ import {JwtClaims} from '@custom-types/jwt_interface'
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class AuthService {
|
||||
private isAuthenticatedSubject = new BehaviorSubject<boolean>(false);
|
||||
public isAuthenticated$ = this.isAuthenticatedSubject.asObservable();
|
||||
private isAuthenticatedSubject = signal<boolean>(false);
|
||||
public readonly isAuthenticated$ = this.isAuthenticatedSubject.asReadonly();
|
||||
|
||||
private userClaimsSubject = new BehaviorSubject<JwtClaims | null>(null);
|
||||
public userClaims$ = this.userClaimsSubject.asObservable();
|
||||
private userClaimsSubject = signal<JwtClaims | null>(null);
|
||||
private jwtHelper = new JwtHelperService();
|
||||
private _username = signal<string | null>(null);
|
||||
public readonly username = this._username.asReadonly();
|
||||
@@ -34,7 +33,7 @@ export class AuthService {
|
||||
return this.loginService.login(code).pipe(
|
||||
tap(jwt => {
|
||||
this.saveJwt(jwt);
|
||||
this.isAuthenticatedSubject.next(true);
|
||||
this.isAuthenticatedSubject.set(true);
|
||||
|
||||
this.reloadUsername();
|
||||
}),
|
||||
@@ -61,8 +60,8 @@ export class AuthService {
|
||||
*/
|
||||
public logout(): void {
|
||||
localStorage.removeItem('jwt');
|
||||
this.isAuthenticatedSubject.next(false);
|
||||
this.userClaimsSubject.next(null);
|
||||
this.isAuthenticatedSubject.set(false);
|
||||
this.userClaimsSubject.set(null);
|
||||
this._username.set(null);
|
||||
}
|
||||
|
||||
@@ -84,8 +83,8 @@ export class AuthService {
|
||||
|
||||
const claims = this.extractJwtClaims(jwt);
|
||||
console.log("User claims: ", claims);
|
||||
this.userClaimsSubject.next(claims);
|
||||
this.isAuthenticatedSubject.next(true);
|
||||
this.userClaimsSubject.set(claims);
|
||||
this.isAuthenticatedSubject.set(true);
|
||||
if (this.username() == null) {
|
||||
this.reloadUsername();
|
||||
}
|
||||
@@ -111,7 +110,7 @@ export class AuthService {
|
||||
|
||||
const claims = this.extractJwtClaims(jwt);
|
||||
console.log("Saving user claims: ", claims);
|
||||
this.userClaimsSubject.next(claims);
|
||||
this.userClaimsSubject.set(claims);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -125,7 +124,7 @@ export class AuthService {
|
||||
* Get user authorizations from claims
|
||||
*/
|
||||
public getUserAuthorizations(): string[] {
|
||||
const claims = this.userClaimsSubject.getValue();
|
||||
const claims = this.userClaimsSubject();
|
||||
return claims?.authorities || [];
|
||||
}
|
||||
|
||||
@@ -135,7 +134,7 @@ export class AuthService {
|
||||
}
|
||||
|
||||
public getUuid(): string | null {
|
||||
const jwtClaims = this.userClaimsSubject.getValue();
|
||||
const jwtClaims = this.userClaimsSubject();
|
||||
if (jwtClaims === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user