Is here any possibility to modify devise SessionsController for ajax communication?
Edit
I found the solution, and posted it into answers, thanks
Is here any possibility to modify devise SessionsController for ajax communication?
I found the solution, and posted it into answers, thanks
1. Generate Devise controllers so we can modify it
Now we have all controllers in the app/controllers/[model] directory
2. Edit routes.rb
Let's set Devise to use our modified SessionsController
First add this code (of course change :users to your devise model) into config/routes.rb
3. Modify sessions_controller.rb
Find the create method and change it to
Create new method after protected
4. devise.rb
Insert this into config/initializers/devise.rb
5. Invalid email or password message
Insert a new message into config/locales/devise.en.yml under the sessions
6. View
The reason why I am using status 200 or 401 unlike {status: 'true'} is less data size, so it is much faster and cleaner.
Explanation
On signing in, you get these data in params
Before signing, you need to authorize the user.
User.find_for_database_authentication
If user is found, resource will be filled with something like
Otherwise will be
If the user is authenticated, we are about to validate his password
And finally sign in
Sources
SessionsController
Helped me Andreas Lyngstad