Module: Roda::RodaPlugins::BetterAuthPlugin::InstanceMethods
- Defined in:
- lib/better_auth/roda/plugin.rb
Instance Method Summary collapse
- #authenticated? ⇒ Boolean
- #current_session ⇒ Object
- #current_user ⇒ Object
- #require_authentication ⇒ Object
Instance Method Details
#authenticated? ⇒ Boolean
67 68 69 |
# File 'lib/better_auth/roda/plugin.rb', line 67 def authenticated? !current_user.nil? end |
#current_session ⇒ Object
57 58 59 60 |
# File 'lib/better_auth/roda/plugin.rb', line 57 def current_session data = better_auth_session_data data&.fetch(:session, nil) || data&.fetch("session", nil) end |
#current_user ⇒ Object
62 63 64 65 |
# File 'lib/better_auth/roda/plugin.rb', line 62 def current_user data = better_auth_session_data data&.fetch(:user, nil) || data&.fetch("user", nil) end |
#require_authentication ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/better_auth/roda/plugin.rb', line 71 def require_authentication return true if authenticated? if prefers_json_response? error = BetterAuth::APIError.new("UNAUTHORIZED") request.halt [ 401, {"content-type" => "application/json"}, [JSON.generate(error.to_h)] ] end request.halt [401, {}, [""]] end |