Last active
July 27, 2019 19:35
-
-
Save nafidurmus/d6f71eb469a885b60f63cb34681bfced to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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