module Admin class BaseController < ActionController::Base include Pagy::Backend # Enable session and flash for admin controllers # (needed because the app is in API-only mode) protect_from_forgery with: :exception layout "admin" before_action :require_admin private def current_admin @current_admin ||= AdminUser.find_by(id: session[:admin_id]) if session[:admin_id] end helper_method :current_admin def logged_in? current_admin.present? end helper_method :logged_in? def require_admin unless logged_in? redirect_to admin_login_path, alert: "Please log in to continue" end end end end