Add JWT support for authentication handling
Integrate `@auth0/angular-jwt` for Token management. Update `app.config.ts` with `JwtModule` setup and token getter from cookies. Enhance `AuthService` to include token handling, fake login, and JWT validation using `JwtHelperService`. Introduce `JwtClaims` interface for structured token claims.
This commit is contained in:
@@ -1,8 +1,26 @@
|
||||
import {ApplicationConfig, provideZoneChangeDetection} from '@angular/core';
|
||||
import {provideRouter} from '@angular/router';
|
||||
import {JwtHelperService, JwtModule} from '@auth0/angular-jwt';
|
||||
import {CookieService} from 'ngx-cookie-service';
|
||||
|
||||
import {routes} from './app.routes';
|
||||
|
||||
// Function to get the JWT token from cookies
|
||||
export function jwtTokenGetter() {
|
||||
const cookieService = new CookieService(document, null);
|
||||
return cookieService.check('jwt') ? cookieService.get('jwt') : null;
|
||||
}
|
||||
|
||||
export const appConfig: ApplicationConfig = {
|
||||
providers: [provideZoneChangeDetection({eventCoalescing: true}), provideRouter(routes)]
|
||||
providers: [
|
||||
provideZoneChangeDetection({eventCoalescing: true}),
|
||||
provideRouter(routes),
|
||||
{ provide: CookieService, useClass: CookieService },
|
||||
{ provide: JwtHelperService, useClass: JwtHelperService },
|
||||
{ provide: JwtModule, useValue: JwtModule.forRoot({
|
||||
config: {
|
||||
tokenGetter: jwtTokenGetter
|
||||
}
|
||||
})}
|
||||
]
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user