Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to require authentication for all pages with Devise?

I have started to use Devise gem and now trying to implement the code, so my web app will require to login for each and every page on my app. I have added the following code to routes.rb according to this instruction:

authenticated :user do
  root to: 'home#index', as: :authenticated_root
end
root to: redirect('/users/sign_in')

but it doesn't work. When I go to any page - it just open that page, and doesn't forward me to the sign_in page. Could anyone please clarify what I missed? Any help would be appreciated.

like image 610
holyavkin Avatar asked Jan 15 '16 21:01

holyavkin


Video Answer


1 Answers

Add this to your app controller

class ApplicationController < ActionController::Base
  ...
  before_action :authenticate_user!
end
like image 195
Dmitry Polyakovsky Avatar answered Oct 10 '22 19:10

Dmitry Polyakovsky