Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8552239
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T14:22:55+00:00 2026-06-11T14:22:55+00:00

I have managed to setup json authentication. I implemented the following code: class Users::

  • 0

I have managed to setup json authentication. I implemented the following code:

class Users:: SessionsController < Devise::SessionsController
  def create
    respond_to do |format|  
      format.html { super }  
      format.json {  
        warden.authenticate!(:scope => resource_name, :recall => "#{controller_path}#failure")  
        render :json => {:success => true}  
      }
    end  
  end

  def destroy
    respond_to do |format|
      format.html {super}
      format.json {  
        Devise.sign_out_all_scopes ? sign_out : sign_out(resource_name)
        render :json => {}
      }
    end
  end

  def failure
    render :json => {:success => false, :errors => ["Login Failed"]}
  end
end

This works fine, but when authentication fails, the failure doesnt return the json failure. I have a custom failure for devise. If I remove the redirect_url or remove the customer failure completely, then the authentication returns a json with the failure message. My custom failure is as follows:

class CustomFailure < Devise::FailureApp
  def redirect_url
    #return super unless [:worker, :employer, :user].include?(scope) #make it specific to a scope
     '/'
  end

  # You need to override respond to eliminate recall
  def respond
    if http_auth?
      http_auth
  else
    redirect
  end
end

end

Anyway to keep the redirect if its an html request, and return a json with a failure msg if its a json request?

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T14:22:56+00:00Added an answer on June 11, 2026 at 2:22 pm

    You have to tell warden to use that custom failure.

    def failure
      respond_to do |format|
        format.html {super}
        format.json do
          warden.custom_failure!
          render :json => {:success => false, :errors => ["Login Failed"]}
        end
      end
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following setup: A model called Categories. These categories are managed using
Have anyone successfully managed to setup a combined Java/C++ project for Eclipse? What I
Setup: I have a COM DLL that calls a method inside a managed C#
Background: We have a TFS server setup where me manage our source code and
I have managed to create a custom action in C# using MakeSfxCA which is
I have managed to bring the following output with this query SELECT DISTINCT IF(purchaseproduct_customerid=0,contactperson,vendorname)
I have managed to setup autocomplete field for my rails app. What I'm trying
I have managed to setup a page so that a user clicks an item
I have managed to setup a blog on localhost quickly using wordpress. But what
I have managed to set up Cassandra + Thrift and the Python wrapper for

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.