Module: BetterAuth::Rails::ControllerHelpers
- Defined in:
- lib/better_auth/rails/controller_helpers.rb
Instance Method Summary collapse
- #authenticated? ⇒ Boolean
- #current_session ⇒ Object
- #current_user ⇒ Object
- #require_authentication ⇒ Object
Instance Method Details
#authenticated? ⇒ Boolean
16 17 18 |
# File 'lib/better_auth/rails/controller_helpers.rb', line 16 def authenticated? !current_user.nil? end |
#current_session ⇒ Object
6 7 8 9 |
# File 'lib/better_auth/rails/controller_helpers.rb', line 6 def current_session data = better_auth_session_data data&.fetch(:session, nil) || data&.fetch("session", nil) end |
#current_user ⇒ Object
11 12 13 14 |
# File 'lib/better_auth/rails/controller_helpers.rb', line 11 def current_user data = better_auth_session_data data&.fetch(:user, nil) || data&.fetch("user", nil) end |
#require_authentication ⇒ Object
20 21 22 23 24 25 |
# File 'lib/better_auth/rails/controller_helpers.rb', line 20 def require_authentication return true if authenticated? head(:unauthorized) if respond_to?(:head) false end |