GUIDE

The road ahead will be long and our climb will be steep

What Can Cause a Cookie Not to Be Set on the Client?

| Comments

Issues

I use ember at cliend, and start on localhost:4200; sinatra at server, start on localhost:9292.

Then I use response.set_cookie() to store user info, but I cannot see cookie setted just now on chrome console -> resource -> cookies -> localhost.

cliend code:

1
2
3
$.ajax({
  url: http://localhost:9292/user
})

cliend code:

1
2
3
4
5
6
response.set_cookie('Cookie-Name',
          :value => value,
          :expires => Time.now + 3600 * 24 * 14,
          :domain => @domain,
          :path => '/',
          :httponly => true)

Solution

Option in ajax:

1
2
3
xhrFields: {
  withCredentials: true
}

Response header in sinatra, Access-Control-Allow-Credentials: true, Access-Control-Allow-Origin: http://localhost:4200

Important

Don’t set localhost as a domain for your cookies because you need to set it to “” or FALSE

Comments