Skip to content

Instantly share code, notes, and snippets.

@nafidurmus
Last active July 27, 2019 19:35
Show Gist options
  • Save nafidurmus/d6f71eb469a885b60f63cb34681bfced to your computer and use it in GitHub Desktop.
Save nafidurmus/d6f71eb469a885b60f63cb34681bfced to your computer and use it in GitHub Desktop.
class ApplicationController < ActionController::API
def authorize_request
header = request.headers['Authorization']
if !header.nil?
header = header.split(' ').last
@decoded_token ||= JsonWebToken.decode(header)
begin
@user = User.find(@decoded_token[:id])
rescue Exception => e
render json: { errors: 'unauthorized' }, status: :unauthorized
end
else
render json: { errors: 'unauthorized' }, status: :unauthorized
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment