Skip to content

Commit

Permalink
Integrate rodauth helpers to grape app
Browse files Browse the repository at this point in the history
  • Loading branch information
davydovanton committed Oct 11, 2016
1 parent 10b1f4d commit 171ddc4
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
22 changes: 22 additions & 0 deletions app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,29 @@ class API < Grape::API
format :json
prefix :api

helpers do
def rodauth
env['rodauth']
end

def authenticate!
error!('401 Unauthorized', 401) unless authenticated?
end

def authenticated?
rodauth.authenticated?
end
end

get :hello do
{ hello: 'world' }
end

namespace :private do
before { authenticate! }

get :hello do
{ hello: 'world' }
end
end
end
3 changes: 1 addition & 2 deletions auth.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ class Auth < Roda
end

route do |r|
env['rodauth'] = rodauth
r.rodauth

rodauth.require_authentication
end
end

0 comments on commit 171ddc4

Please sign in to comment.