Jetty + React - Cookie nicht eingestellt wirdJava

Java-Forum
Anonymous
 Jetty + React - Cookie nicht eingestellt wird

Post by Anonymous »

Ich habe diesen Beitrag verfolgt. />@Provider
public class CorsFilter implements Filter {

@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
throws IOException, ServletException {

final HttpServletResponse httpResponse = (HttpServletResponse) response;
httpResponse.addHeader("Access-Control-Allow-Origin", "http://localhost:3000"); // React running on port 3000
httpResponse.addHeader("Access-Control-Allow-Credentials", "true");
httpResponse.addHeader("Access-Control-Allow-Headers", "Content-Type, Authorization");

chain.doFilter(request, response);
}
}
< /code>
und in React Frontend habe ich < /p>
return fetch('http://localhost:8080/user/login', {
method: 'POST',
credentials: 'include',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
username: username,
password: password
})
})
< /code>
Wenn ich den Browser auf Cookies überprüfe, werden sie nicht eingestellt. Eine Idee, warum nicht?

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post