Definition of strange:
My app’s session model seems to work fine. The cookie (user.remember_token = SecureRandom.urlsafe_base64) is stored, the signin persists. Life is good.
Yet, when a user edits their profile and clicks submit, they are logged out.
This SO Question makes me think that Rails is ending the session because of XSRF.
But why?
Instead of posting all my code here, one link gets it all: https://github.com/chiperific/arcwmi_reports
Help!
Your problem is in the
Usermodel:This will modify the remember_token whenever the user is saved – that is, when the user is created or updated. And when a user updates his/her profile, the remember_token is changed. This causes the login system to notice that the cookie no longer matches the user – and logs the user out.
The fix – use
before_createinstead ofbefore_save.