theseus/app/controllers/application_controller.rb
2025-12-29 10:39:37 -05:00

36 lines
965 B
Ruby
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

class ApplicationController < ActionController::Base
include Pundit::Authorization
after_action :verify_authorized
helper_method :current_user, :user_signed_in?
before_action :authenticate_user!, :set_sentry_context
def current_user
@current_user ||= User.find_by(id: session[:user_id]) if session[:user_id]
end
def user_signed_in?
!!current_user
end
def authenticate_user!
unless user_signed_in?
redirect_to login_path, alert: ("you need to be logged in!" unless request.env["PATH_INFO"] == "/back_office")
end
end
def set_sentry_context
Sentry.set_user(id: current_user&.id, email: current_user&.email)
end
rescue_from Pundit::NotAuthorizedError do |e|
flash[:error] = "you don't seem to be authorized ask nora?"
redirect_to root_path
end
rescue_from ActiveRecord::RecordNotFound do |e|
flash[:error] = "sorry, couldn't find that object... (404)"
redirect_to root_path
end
end