-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Closed
Description
Hi,
I searched around, posted in stackoverflow, but I got no solution so far.
I'm trying to give a custom json response in case of failed login. I want the json to be in this format:
{success: false, errors: [<error_message>]}
So I overrode the SessionsContoller, as following:
class SessionsController < Devise::SessionsController
respond_to :json
def create
self.resource = warden.authenticate!(auth_options)
sign_in(resource_name, resource)
render json: { :success => true }, status: 200
end
def failure
warden.custom_failure!
render json: { success: false, errors: ["Login Credentials Failed"] }, status: 401
end
protected
def auth_options
{:scope => resource_name, :recall => "#{controller_path}#failure"}
end
endroutes.rb:
devise_for :users, controllers: {sessions: 'sessions'}devise.rb:
config.navigational_formats = ["*/*", :html, :json]Login is working just fine, I'm just not being able to override the failure response. I'm just posting this here to check if it's not a bug, since this same code is presented in various blog posts in the internet.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels