I'm doing a singe-page application using Rails. When signing in and out Devise controllers are invoked using ajax. The problem I'm getting is that when I 1) sign in 2) sign out then signing in again doesn't work.
I think it's related to CSRF token which gets reset when I sign out (though it shouldn't afaik) and since it's single page, the old CSRF token is being sent in xhr request thus resetting the session.
To be more concrete this is the workflow:
- Sign in
- Sign out
- Sign in (successful 201. However prints
WARNING: Can't verify CSRF token authenticity
in server logs)
- Subsequent ajax request fails 401 unauthorised
- Refresh the website (at this point, CSRF in the page header changes to something else)
- I can sign in, it works, until I try to sign out and in again.
Any clues very much appreciated! Let me know if I can add any more details.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…