From 3edf5cc41cc88d36c897e27d04b5ac0c11f0833e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bernhard=20M=C3=BCller?= Date: Mon, 27 Jul 2026 18:16:12 +0200 Subject: [PATCH] fix(backend): fixed cors error on build dev environment --- .../mueller/eeg/backend/iam/config/SecurityConfig.java | 3 +-- eeg_frontend/src/app/interceptors/jwt.interceptor.ts | 9 +++------ 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/eeg_backend/src/main/java/at/mueller/eeg/backend/iam/config/SecurityConfig.java b/eeg_backend/src/main/java/at/mueller/eeg/backend/iam/config/SecurityConfig.java index ad67fab..be47bae 100644 --- a/eeg_backend/src/main/java/at/mueller/eeg/backend/iam/config/SecurityConfig.java +++ b/eeg_backend/src/main/java/at/mueller/eeg/backend/iam/config/SecurityConfig.java @@ -30,7 +30,6 @@ import org.springframework.web.cors.UrlBasedCorsConfigurationSource; import javax.crypto.spec.SecretKeySpec; import java.util.Arrays; -import java.util.List; @Configuration @EnableWebSecurity @@ -94,7 +93,7 @@ public class SecurityConfig { CorsConfiguration configuration = new CorsConfiguration(); configuration.setAllowedOrigins(Arrays.stream(corsOrigins.split(",")).map(String::trim).toList()); configuration.setAllowedMethods(Arrays.asList("GET", "POST", "PUT", "DELETE", "OPTIONS", "PATCH")); - configuration.setAllowedHeaders(Arrays.asList("Authorization", "Content-Type")); + configuration.setAllowedHeaders(Arrays.asList("Authorization", "Content-Type", "X-Access-Token")); configuration.setAllowCredentials(true); UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); source.registerCorsConfiguration("/**", configuration); diff --git a/eeg_frontend/src/app/interceptors/jwt.interceptor.ts b/eeg_frontend/src/app/interceptors/jwt.interceptor.ts index 9045ef8..31d6570 100644 --- a/eeg_frontend/src/app/interceptors/jwt.interceptor.ts +++ b/eeg_frontend/src/app/interceptors/jwt.interceptor.ts @@ -3,14 +3,11 @@ import {HttpInterceptorFn} from '@angular/common/http'; export const jwtInterceptor: HttpInterceptorFn = (req, next) => { const token = localStorage.getItem('token'); - // If a token exists, clone the request and add the Authorization header if (token) { - const clonedRequest = req.clone({ - setHeaders: { - Authorization: `Bearer ${token}` - } + const authReq = req.clone({ + headers: req.headers.set('X-Access-Token', token) }); - return next(clonedRequest); + return next(authReq); } return next(req);