Sha256: 85e85f6ef59cd82ef7bd8f35d139b59f937af73f863cdc6b19b92b7d76167b4e
Contents?: true
Size: 1.14 KB
Versions: 1
Compression:
Stored size: 1.14 KB
Contents
module Auth0CurrentUser module WebSecured extend ActiveSupport::Concern included do before_action :logged_in_using_omniauth? helper_method :current_user end def current_user @_current_user ||= Kernel.const_get(authenticated_klass).find_by(email: email) end private def authenticated_klass unless configuration.authenticated_klass raise NotImplementedError, 'You must define the #authenitcated_klass in config/initializers/auth0_current_user' return end @_authenticated_klass ||= configuration.authenticated_klass.to_s.classify rescue NameError => e Rails.logger.error("You must create a #{authenticated_klass} model/migration") rescue StandardError => e Rails.logger.error(e.message) end def configuration @_configuration ||= Configuration.new end def email @_email ||= userinfo['email'] || userinfo['name'] end def logged_in_using_omniauth? redirect_to '/' unless session[:userinfo].present? && Time.zone.now < Time.zone.at(userinfo['exp']) end def userinfo session['userinfo'] || {} end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
auth0_current_user-0.2.1 | lib/auth0_current_user/web_secured.rb |