Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

spring + angular + session cookies

I am developing an application with a springboot backend and an angular frontend.

Both will be deployed under the same domain. So I will use cookies to maintain the session.

But for development the spring services backend is on localhost:8080 and the angular app is on localhost:4200

I would like to be able to share the cookie on localhost for the different ports. How can I do this?

When I make a call to localhost:8080/api/service I can see in the response a Set-Cookie: JSESSIONID=A2DD58970CB3E8B9DD4F3BF1444D5E55; Path=/api; HttpOnly But on the next call the cookie is not sent.

I have decided to use cookies instead of sending a token in the header after reading this guide.

I don't have any strange configuration, but I understand that it must be due to a security problem. how can I disable this security control for development? What do you do in such cases?

like image 624
user60108 Avatar asked Sep 14 '26 17:09

user60108


1 Answers

I have managed to fix it

From angular side using this.http.get('http://...', { withCredentials: true })

From spring side adding cors configuration with .allowCredentials(true)

like image 140
user60108 Avatar answered Sep 17 '26 07:09

user60108