2026-06-10 16:16:28 +00:00
|
|
|
class ApplicationController < ActionController::API
|
|
|
|
|
include Renderable
|
|
|
|
|
|
2026-05-30 21:27:35 +00:00
|
|
|
before_action :authenticate!
|
|
|
|
|
|
2026-06-10 16:16:28 +00:00
|
|
|
rescue_from Unauthorized do
|
|
|
|
|
render_error("Unauthorized", :unauthorized)
|
|
|
|
|
end
|
2026-06-10 15:51:32 +00:00
|
|
|
|
2026-05-30 21:27:35 +00:00
|
|
|
private
|
|
|
|
|
def authenticate!
|
|
|
|
|
token = request.headers["Authorization"]&.split(" ")&.last
|
2026-06-14 11:12:37 +00:00
|
|
|
@current_session = Session.find_by(token: token)
|
|
|
|
|
raise Unauthorized unless @current_session
|
2026-06-10 15:51:32 +00:00
|
|
|
|
2026-06-14 11:12:37 +00:00
|
|
|
@current_user = @current_session.user
|
2026-05-30 21:27:35 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def current_user
|
|
|
|
|
@current_user
|
|
|
|
|
end
|
2026-06-14 11:12:37 +00:00
|
|
|
|
|
|
|
|
def current_session
|
|
|
|
|
@current_session
|
|
|
|
|
end
|
2026-05-17 11:12:43 +00:00
|
|
|
end
|