playground/app/controllers/application_controller.rb
2026-05-17 03:44:36 +00:00

23 lines
635 B
Ruby

class ApplicationController < ActionController::Base
include Authentication
# Only allow modern browsers supporting webp images, web push, badges, import maps, CSS nesting, and CSS :has.
allow_browser versions: :modern
# Changes to the importmap will invalidate the etag for HTML responses
stale_when_importmap_changes
helper_method :current_user
private
def current_user
@current_user ||= User.find_by(id: session[:user_id]) if session[:user_id]
end
def authenticate_user!
unless Current.user
redirect_to new_session_path, alert: "You must be logged in to access this page."
end
end
end