79380166

Date: 2025-01-23 07:32:27
Score: 3
Natty:
Report link

Thank you for the support. This issue has been solved.

Actually, I read an article on Medium that told me about the way to resolve CORS errors in the Spring application by allowing headers, origins, and many other things. That resolved the issue, and login registration functionality was working fine.

But when I implemented the Cart Page, which is a secured route and requires an authentication token to be sent with the request, then the authorization token was not reaching the Spring application.

So, I read the documentation of Spring and looked for many solutions on YouTube. After some time, I found a video on YouTube.

Youtube LInk: https://youtu.be/uMJnAxapF7E?si=u5myiwDTOIVmpxqk

So what I did, I Still configured the Cors setting but this time, I configuired WebMvcConfigure as FOllows:

@Configuration

public class WebConfig {

@Bean
public WebMvcConfigurer corsConfig() {
    return new WebMvcConfigurer() {
        @Override
        public void addCorsMappings(CorsRegistry registry) {
            registry.addMapping("/**")
                    .allowedOrigins("http://localhost:5173")
                    .allowedMethods(HttpMethod.GET.name(),
                            HttpMethod.POST.name(),
                            HttpMethod.DELETE.name(),
                            HttpMethod.PUT.name())
                    .allowedHeaders(HttpHeaders.CONTENT_TYPE,
                            HttpHeaders.AUTHORIZATION);
        }
    };
}

}

One more thing:

This is the SecurityFilterChain Configuration

Reasons:
  • Blacklisted phrase (0.5): Thank you
  • Blacklisted phrase (1.5): any solution
  • Blacklisted phrase (1): youtu.be
  • Long answer (-1):
  • Has code block (-0.5):
  • Self-answer (0.5):
  • Low reputation (1):
Posted by: Aditya verma