When user enters our web site's root or logs out, Devise authentication displays "You need to sign in or sign up before continuing" the first time. After page reload this message disappears.
Root of our web site is set to controller which has:
before_filter :authenticate_user!
We need this controller to be the root. How to eliminate this message?
The correct solution would be to set an authenticated block as noted in the official wiki: https://github.com/plataformatec/devise/wiki/How-To:-Require-authentication-for-all-pages
authenticated :user do
root to: 'home#index', as: :authenticated_root
end
root to: redirect('/users/sign_in')
The scoped authenticated
block will only be called once they are logged in, so you can happily direct users to a controller of your choice. In the example it redirects them to the sign in page when unauthenticated, but this could be any action in your routes.
I did not find the solution better than defining
unauthenticated: ''
in /config/locales/devise.en.yml file.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With