1

Upon receiving a server response with valid "set-cookie" value in my response header, application does not save the cookie.

Rails server on heroku is setup for CORS (cross domain ajax requests). Access-Control-Allow-Credentials = True and methods = POST, GET.

Login request, for which the response contains set-cookie, is as follows:

 Ext.Ajax.request({
            url: 'http://myurl/log_user_in.json',
            params: { username: user, password: pass, app_id: id },
            method: "POST" });

Need help on why the application does not save the cookie. ie. executing document.cookie , after getting "set-cookie" results in document.cookie = ''

Thanks for your help.

Austin
  • 3,556
  • 2
  • 16
  • 16

1 Answers1

3

Found the answer here: https://stackoverflow.com/a/7189502/1106877

Unfortunately Sencha Forum answers provided almost no guidance on how to do this. In Sencha Touch, the equivalent solution to what the link above says is:

Ext.Ajax.request({
            url: 'http://myurl/log_user_in.json',
            params: { username: user, password: pass, app_id: id },
            withCredentials: true,
            useDefaultXhrHeader: false,
            method: "POST" });

It also works well with your store proxy using Ajax.

Ensure withCredentials is true and useDefaultXhreader is false. This permits your ajax request to look for, set, and request with cookies as available. Of course all this assumes your server is setup for Cross Domain Ajax calls.

Community
  • 1
  • 1
Austin
  • 3,556
  • 2
  • 16
  • 16