diff --git a/frontend/src/app/app.config.ts b/frontend/src/app/app.config.ts index 34333cf..fb79305 100644 --- a/frontend/src/app/app.config.ts +++ b/frontend/src/app/app.config.ts @@ -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]) + ), ] }; diff --git a/frontend/src/app/services/AuthInterceptor.ts b/frontend/src/app/services/AuthInterceptor.ts new file mode 100644 index 0000000..135d659 --- /dev/null +++ b/frontend/src/app/services/AuthInterceptor.ts @@ -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); +}; diff --git a/open_api/src/main/resources/schemas/login/login.yml b/open_api/src/main/resources/schemas/login/login.yml index 67c2bd9..5fbb424 100644 --- a/open_api/src/main/resources/schemas/login/login.yml +++ b/open_api/src/main/resources/schemas/login/login.yml @@ -68,6 +68,8 @@ GetUsername: - login summary: Get the username for the logged in user operationId: getUsername + security: + - bearerAuth: [ ] responses: '200': description: Username retrieved