Modified authentication with user_signed_in? and current_user
Some checks are pending
CI / scan_ruby (push) Waiting to run
CI / scan_js (push) Waiting to run
CI / lint (push) Waiting to run
CI / test (push) Waiting to run

This commit is contained in:
2024-08-25 01:20:55 +02:00
parent 0b4825dcbb
commit abe9267893
3 changed files with 36 additions and 25 deletions

View File

@@ -3,10 +3,24 @@ class ApplicationController < ActionController::Base
before_action :authenticate
private
def current_user
Current.user || authenticate_user_from_session
end
helper_method :current_user
def authenticate_user_from_session
session_record = Session.find_by_id(cookies.signed[:session_token])
Current.session = session_record
Current.user
end
def user_signed_in?
current_user.present?
end
helper_method :user_signed_in?
def authenticate
if session_record = Session.find_by_id(cookies.signed[:session_token])
Current.session = session_record
else
unless user_signed_in?
redirect_to sign_in_path
end
end