Skip to content

Commit

Permalink
Update set up authorization (#4)
Browse files Browse the repository at this point in the history
Add a custom auth constraint in case you are not using devise or basic auth
  • Loading branch information
scart88 authored Sep 29, 2024
1 parent b261a19 commit 728f778
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,30 @@ To install Spectator Sport in your Rails application:
end
```
If you are using an authentication similar to the one used in ONCE products, you can use an auth constraint in your routes:
```ruby
# config/routes.rb
class AuthRouteConstraint
def matches?(request)
return false unless request.session[:user_id]
user = User.find request.session[:user_id]
if user && user.admin?
cookies = ActionDispatch::Cookies::CookieJar.build(request, request.cookies)
token = cookies.signed[:session_token]
return user.sessions.find_by(token: token)
end
end
end
Rails.application.routes.draw do
namespace :admin, :constraints => AuthRouteConstraint.new do
mount SpectatorSport::Dashboard::Engine, at: 'spectator_sport_dashboard', as: :spectator_sport_dashboard
end
```
Or extend the `SpectatorSport::Dashboard::ApplicationController` with your own authorization logic:
```ruby
# config/initializers/good_job.rb
Expand Down

0 comments on commit 728f778

Please sign in to comment.