4
votes

I need my Rails app to only allow users with :admin to be able to access the sign_up page and add users. However, if someone is signed in (admin or otherwise), Devise redirects them and displays the "already signed in" message bound to the already_authenticated error.

I know there are other, more robust ways around this like creating a new controller to override the standard one in Devise, but because I am fairly new to Rails and my current needs are small I simply wanted to disable that "already_authenticated" redirect entirely. Then, I could easily add an "if" statement to the top of the sign_up page to keep regular users out of it, but still let those with :admin attributes pass. I could do the same with the sign_in page and start it with an "if signed_in?" query to see if a user is currently signed in and redirect as necessary on my own. Easy peasy (I think).

I've been pouring through the Devise docs and their lib files but haven't been able to locate exactly where this redirect is being handled, if that is indeed what it's doing at all.

Any help is appreciated and thank you in advance.

1

1 Answers

0
votes

Redirects are here: https://github.com/plataformatec/devise/blob/master/app/controllers/devise/sessions_controller.rb and https://github.com/plataformatec/devise/blob/master/app/controllers/devise/registrations_controller.rb

prepend_before_filter :require_no_authentication, :only => [ :new, :create ]

As you see from source code there is no way to disable it with config options. The only way is to override appropriate controller.