trestle-auth icon indicating copy to clipboard operation
trestle-auth copied to clipboard

Configure trestle to only accept admin users?

Open Bandes opened this issue 3 years ago • 3 comments

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 }

Bandes avatar Aug 18 '21 01:08 Bandes

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

dcalixto avatar Sep 21 '21 22:09 dcalixto

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

ohpreis avatar Nov 09 '21 21:11 ohpreis

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

zealot128 avatar Aug 29 '22 19:08 zealot128