Integrate authInterceptor for JWT handling, update API schema with bearerAuth security, and refactor configuration to support HTTP interceptors.
This commit is contained in:
parent
238c5d9644
commit
e825d83124
|
|
@ -3,11 +3,16 @@ import {provideRouter} from '@angular/router';
|
|||
import {CookieService} from 'ngx-cookie-service';
|
||||
|
||||
import {routes} from './app.routes';
|
||||
import {provideHttpClient, withInterceptors} from '@angular/common/http';
|
||||
import {authInterceptor} from '@services/AuthInterceptor';
|
||||
|
||||
export const appConfig: ApplicationConfig = {
|
||||
providers: [
|
||||
provideZoneChangeDetection({eventCoalescing: true}),
|
||||
provideRouter(routes),
|
||||
CookieService,
|
||||
provideHttpClient(
|
||||
withInterceptors([authInterceptor])
|
||||
),
|
||||
]
|
||||
};
|
||||
|
|
|
|||
19
frontend/src/app/services/AuthInterceptor.ts
Normal file
19
frontend/src/app/services/AuthInterceptor.ts
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
import {HttpInterceptorFn} from '@angular/common/http';
|
||||
import {inject} from '@angular/core';
|
||||
import {AuthService} from '@services/auth.service';
|
||||
|
||||
export const authInterceptor: HttpInterceptorFn = (req, next) => {
|
||||
const authService = inject(AuthService);
|
||||
const jwt = authService.getJwt();
|
||||
|
||||
if (jwt) {
|
||||
const authReq = req.clone({
|
||||
setHeaders: {
|
||||
Authorization: `Bearer ${jwt}`
|
||||
}
|
||||
});
|
||||
return next(authReq);
|
||||
}
|
||||
|
||||
return next(req);
|
||||
};
|
||||
|
|
@ -68,6 +68,8 @@ GetUsername:
|
|||
- login
|
||||
summary: Get the username for the logged in user
|
||||
operationId: getUsername
|
||||
security:
|
||||
- bearerAuth: [ ]
|
||||
responses:
|
||||
'200':
|
||||
description: Username retrieved
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user