# frozen_string_literal: true module NulogySSO # A mix-in that is intended to enhance a controller with NulogySSO authentication code. # It is recommended to `include NulogySSO::ControllerHelper` in your ApplicationController. module ControllerHelper extend ActiveSupport::Concern included do # Makes the commonly used @current_user variable available to controllers and views. # This emulates a code pattern popular in Rails apps using Devise. attr_reader :current_user helper_method :current_user before_action :store_previous_url_in_session end def authenticate_sso_user raw_token = cookies[NulogySSO.auth_cookie_key] return redirect_to nulogy_sso.login_path if raw_token.blank? @current_user = Authenticator.new.authenticated_user(raw_token) return redirect_to nulogy_sso.login_path if @current_user.blank? end def store_previous_url_in_session session[:previous_request_url] = request.url unless current_user end end end