I'm building an small API in sinatra. I need to authenticate the routes, and I have that already working doing the following (as read from the documentation)
use Rack::Auth::Basic,"Protected Area" do |username, password|
user = User.validate username, password
end
But I'll have multiple users, so I'm doing something like this:
class Protected < Sinatra::Base
use Rack::Auth::Basic,"Protected Area" do |username, password|
User.validate username, password
end
get '/users' do
content_type :json
#I want to return the user who was authenticated
end
end
The class method Validate returns the user if the user does exists in the database or returns false if it doesn't exists. But what I have no idea how to do is how to access that user from inside a route, for example get '/users' do
Thanks!