Class: Trestle::Auth::Constraint

Inherits:
Object
  • Object
show all
Defined in:
lib/trestle/auth/constraint.rb

Overview

Trestle::Auth::Constraint is a Rails routing constraint that can be used to protect segments of your application that aren’t regular Trestle admins or resources (all of which are automatically protected).

Note that when using a Rails routing constraint like this one, any unauthenticated requests will return a 404 (Not Found) rather than a redirect to the login page.

Examples

mount Sidekiq::Web => "/sidekiq/web", constraints: Trestle::Auth::Constraint.new

constraints Trestle::Auth::Constraint.new do
  get "/custom/action", to 'custom#action'
end

Instance Method Summary collapse

Instance Method Details

#matches?(request) ⇒ Boolean

Returns:

  • (Boolean)


19
20
21
22
23
# File 'lib/trestle/auth/constraint.rb', line 19

def matches?(request)
  backend = authentication_backend_for(request)
  backend.authenticate
  backend.logged_in?
end