TrestleAdmin / trestle-auth

Authentication plugin for the Trestle admin framework
https://trestle.io
GNU Lesser General Public License v3.0
53 stars 22 forks source link

Configure trestle to only accept admin users? #37

Open Bandes opened 3 years ago

Bandes commented 3 years ago

Hi - I am confused by how trestle-auth works, I have a User model in Devise which has an admin boolean on it. I would like to limit access to all of Trestle to only users with admin == true - it seems like that might be what trestle-auth is for, but I can't figure out how to get it set up.

Does it have something to do with this

  # Specify the parameter (along with a password) to be used to
  # authenticate an administrator. Defaults to :email if not specified below.
  #
  config.auth.authenticate_with = -> { Devise.authentication_keys.first }
dcalixto commented 3 years ago

Yes, i'm confused with this too, and now after setup trestle-auth the devise user did not login anymore!

ohpreis commented 2 years ago

Same here. How would I limit access to Trestle to admins only? I also use Devise.

zealot128 commented 2 years ago

In my case it was simply setting a before_action in config/initializers/trestle.rb

  config.before_action do |_controller|
    unless current_user.admin?
      redirect_to '/'
    end
  end