huafu / ember-data-sails

Adapters and tools for Ember to work well with Sails
MIT License
61 stars 31 forks source link

CSRF mismatch when sails restarted #25

Open shopapps opened 9 years ago

shopapps commented 9 years ago

Hi,

Is there an easy way for me to fix the issue where if I restart my sails server, then the Ember App reconnects the socket ok, however it does not refresh the CSRF token and so when i try and save a record I get an error Code 403 - CSRF mismatch from the sails server.

I tried inserting

this.set('csrfToken', false);

into line 380 of services/sails-socket.js but it did not seem to help me.. anyone else come across this issue before?

thanks.

Paul.

shopapps commented 9 years ago

Has anyone else experienced this or found a workaround at all? - thanks.

huafu commented 9 years ago

As a workaround until I have time to work on this, you can call adapter.fetchCSRFToken(true) which is a promise.

(pm: sorry to answer that late, so so busy lately)

shopapps commented 9 years ago

That's no problem, thanks for your help.

Actually as an FYI, I did some more googling and discovered that by changing the session store in my sailsjs api (from internal memory to mongo in my case, but I assume redis would be the same), then the client side stored CSRF token is still 'valid' after a restart of the API.

So this masks/resolves the issue for me, but am still not sure if its a ember-data-sails problem or a sailsjs configuration issue.