class ApplicationController < ActionController::Base before_action :authenticate_user! helper_method :current_user helper_method :authenticate_user! def authenticate_user! if current_user.blank? respond_to do |format| format.html { redirect_to "/auth/infinum?origin=#{request.url}" } format.json { render :json => { 'error' => 'Access Denied' }.to_json } end end end def current_user return nil unless session[:user_id] @current_user ||= User.new_from_omniauth(session[:user_id]) end # Prevent CSRF attacks by raising an exception. # For APIs, you may want to use :null_session instead. protect_from_forgery with: :exception end