简体   繁体   中英

Ember: session cookie from api not being set

I am trying to set a session cookie from my back-end API for a particular ember-data model ('cart').

When createRecord is called on the model, I see the XHR "POST" request to my API. I see the API process it and respond, and I see the Set-Cookie in the response headers...but no cookie in the browser!

The ember app and the api are on the same domain (localhost), though on different ports. I googled and it appears that cookies are not port-specific . So I can't see what's preventing it.

I tried using the Chrome extension Postman to submit the same POST to the API and it works just fine - sets the cookie in the browser. Just doesn't work when the request comes from the ember app. Though I am not seeing any errors anywhere.

Is there something within ember that's preventing the cookie from being set? I can't see why there would be, I think the browser should be processing the response headers before ember comes back into play.

I'm going down the rabbit hole of death on this! Any help appreciated. Here's the request/response.

在此处输入图片说明

If you are trying a cross domain request you may have to grant permissions both on the app as well as on the server. Read on CORS if that is the case. Also if you have httpOnly cookie, you will have to set withCredientials field in your ajax request as:

      xhrFields: {
        withCredentials: true
      }

You can read more on withCredential here . These two are the major factors for cookie problems.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM