title: Angular Spring Boot Cookies on localhost
body: <p>I have Angular 7 as frontend and Spring Boot as backend. </p>
  
  <p>Angular app hosted on localhost:4200 and Spring app hosted on localhost:8080</p>
  
  <p>On user login, I'm saving a spring session and a cookie is returned. When the user tries to login again, I first check whether the session exists.</p>
  
  <p>For this, the cookie is required from the client. But I'm not getting any cookie in the client request. </p>
  
  <p>In Chrome dev tools, Application tab, following cookie can be seen:</p>
  
  <p><a href="https://i.stack.imgur.com/TETth.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/TETth.png" alt="enter image description here"></a></p>
  
  <p>In Spring Boot's application.properties, I have:</p>
  
  <pre><code>spring.session.store-type=jdbc
  spring.session.jdbc.initialize-schema=always
  server.servlet.session.timeout=60
  spring.session.jdbc.table-name=SPRING_SESSION
  server.servlet.session.cookie.max-age=2592000
  </code></pre>
  
  <p>In controller:</p>
  
  <pre><code>@RestController
  @CrossOrigin(allowCredentials = "true", origins = {"http://localhost:4200", "http://127.0.0.1:4200"})
  @RequestMapping(value = "/users")
  public class UsersController {    
      ...
  
      @RequestMapping(value = "/login", method = RequestMethod.GET)
      public ResponseEntity&lt;?&gt; login(HttpServletRequest request, HttpServletResponse response) {
  
          Cookie[] cookies = request.getCookies();
          if(cookies != null) {
            for (int i = 0; i &lt; cookies.length; i++) {
                String cookieName = cookies[i].getName();
                String cookieValue = cookies[i].getValue();
                logger.info("UsersController - cookie - {} {}", cookieName, cookieValue);
             }
          }
          HttpSession springsession = request.getSession(false);
          if (springsession != null) {
              logger.info("UsersController - login - session exists");            
              ...
          }       
  
          logger.info("UsersController - login - session does not exist");
          ...
      }
  </code></pre>
  
  <p>I'm not getting any cookie in the client request.</p>
  
  <p>Whereas when I try multiple login requests from the Postman, it works.</p>
  
  <p>So why doesn't it work from browser?</p>
  
  <p>I have tried setting server.servlet.session.cookie.domain property to null, false, 127.0.0.1. But none worked.</p>
  
  <p>How can this be solved?</p>