This repo is a simple demonstration how to use devise with a Single Page App.
Conceptually, the Devise views are one modules, while posts/index.html could represent a JS SPA.
posts/index.html is available to anyone, but all it does is initializing some JS. The JS code tries to GET data (ajax) from /posts/index.json. This action has “authorize_user!” in it, so it returns error code. The ‘error’ ajax callback redirects to “users/sign_in”. After logging in, all works fine, thanks to cookies.