18 lines
438 B
Ruby
18 lines
438 B
Ruby
module ApplicationController
|
|
extend ActionController::API
|
|
before_action :authenticate!
|
|
|
|
rescue_from Unauthorized, with: -> { render json: { error: "Unauthorized" }, status: :unauthorized }
|
|
|
|
private
|
|
def authenticate!
|
|
token = request.headers["Authorization"]&.split(" ")&.last
|
|
@current_user = Session.find_by(token:)&.user
|
|
|
|
raise Unauthorized unless @current_user
|
|
end
|
|
|
|
def current_user
|
|
@current_user
|
|
end
|
|
end
|