Directly initialize JwtHelperService in auth service
This commit is contained in:
parent
04310e1cce
commit
42f0961f13
|
|
@ -1,29 +1,13 @@
|
||||||
import {ApplicationConfig, importProvidersFrom, provideZoneChangeDetection} from '@angular/core';
|
import {ApplicationConfig, provideZoneChangeDetection} from '@angular/core';
|
||||||
import {provideRouter} from '@angular/router';
|
import {provideRouter} from '@angular/router';
|
||||||
import {JwtHelperService, JwtModule} from '@auth0/angular-jwt';
|
|
||||||
import {CookieService} from 'ngx-cookie-service';
|
import {CookieService} from 'ngx-cookie-service';
|
||||||
|
|
||||||
import {routes} from './app.routes';
|
import {routes} from './app.routes';
|
||||||
|
|
||||||
export function jwtTokenGetter() {
|
|
||||||
return localStorage.getItem('jwt');
|
|
||||||
}
|
|
||||||
|
|
||||||
export const appConfig: ApplicationConfig = {
|
export const appConfig: ApplicationConfig = {
|
||||||
providers: [
|
providers: [
|
||||||
provideZoneChangeDetection({eventCoalescing: true}),
|
provideZoneChangeDetection({eventCoalescing: true}),
|
||||||
provideRouter(routes),
|
provideRouter(routes),
|
||||||
CookieService,
|
CookieService,
|
||||||
{
|
|
||||||
provide: JwtHelperService,
|
|
||||||
useValue: new JwtHelperService()
|
|
||||||
},
|
|
||||||
importProvidersFrom(
|
|
||||||
JwtModule.forRoot({
|
|
||||||
config: {
|
|
||||||
tokenGetter: jwtTokenGetter
|
|
||||||
}
|
|
||||||
})
|
|
||||||
)
|
|
||||||
]
|
]
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -15,11 +15,11 @@ export class AuthService {
|
||||||
|
|
||||||
private userClaimsSubject = new BehaviorSubject<JwtClaims | null>(null);
|
private userClaimsSubject = new BehaviorSubject<JwtClaims | null>(null);
|
||||||
public userClaims$ = this.userClaimsSubject.asObservable();
|
public userClaims$ = this.userClaimsSubject.asObservable();
|
||||||
|
private jwtHelper = new JwtHelperService();
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private loginService: LoginService,
|
private loginService: LoginService,
|
||||||
private snackBar: MatSnackBar,
|
private snackBar: MatSnackBar
|
||||||
private jwtHelper: JwtHelperService
|
|
||||||
) {
|
) {
|
||||||
// Check if user is already logged in on service initialization
|
// Check if user is already logged in on service initialization
|
||||||
this.checkAuthStatus();
|
this.checkAuthStatus();
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user