fix(backend): fixed cors error on build dev environment
This commit is contained in:
parent
67e1ed144f
commit
3edf5cc41c
@ -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);
|
||||
|
||||
@ -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);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user