Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does anyone know the options for Devises `authenticate_user!`?

Like the title says, I'm looking for the options for devises automatic class authenticate_user!, specifically, I want it to redirect_to to '/' and not '/users/sign_in'

like image 650
Vasseurth Avatar asked Feb 23 '23 15:02

Vasseurth


2 Answers

Do the following:

In config/initializers/devise.rb:

  config.warden do |manager| 
    manager.failure_app = CustomAuthenticationFailure 
  end

Create a new file called lib/custom_authentication_failure.rb:

  class CustomAuthenticationFailure < Devise::FailureApp 
  protected 
    def redirect_url 
      root_path  #or whatever route in your app that points to '/' 
    end 
  end 

And this to your config/application.rb:

  config.autoload_paths += %W(#{config.root}/lib) 
like image 110
Kevin Tsoi Avatar answered Feb 26 '23 04:02

Kevin Tsoi


I think you can find your answer here: Devise Wiki

In particular, I think this should do the trick:

Change default sign in and sign out routes

like image 25
Benjamin Tan Wei Hao Avatar answered Feb 26 '23 04:02

Benjamin Tan Wei Hao