Angular 5 - Cookie is set although (Set-Cookie) is in the response header

泪湿孤枕 提交于 2019-12-06 01:35:24

问题


For an Angular 5 app, I have an auth service that does a HTTP POST which returns the session cookie (CORS) as shown below in the code below:

signIn(signInRequest: SignInRequest): Observable<SignInResponse> {
   let headers: Headers = new Headers();   
   headers.append('Content-Type','application/json');  
   return this.http
              .post("/login", {email:  signInRequest._email,password:signInRequest._password}, { headers: headers, withCredentials: true })
  .map(this.extractData)
  .catch(this.handleErrorObservable);}

The response of the header contains the set-cookie as shown below:

and the request header is the following:

I know that the browser should be setting the cookie response. Why is it not doing it?


回答1:


Your frontend is hosted on localhost:4200 and your backend is hosted on api.safra.me. By default, your browser won't send the cookies along the request unless you use the withCredentials in the login request as you already did, and all of the subsequent requests.



来源:https://stackoverflow.com/questions/49392275/angular-5-cookie-is-set-although-set-cookie-is-in-the-response-header

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!