Class: Clerk::Proxy
- Inherits:
-
Object
- Object
- Clerk::Proxy
- Defined in:
- lib/clerk/rack_middleware.rb
Instance Attribute Summary collapse
-
#error ⇒ Object
readonly
Returns the value of attribute error.
-
#session_id ⇒ Object
readonly
Returns the value of attribute session_id.
Instance Method Summary collapse
- #debug ⇒ Object
-
#initialize(env) ⇒ Proxy
constructor
A new instance of Proxy.
- #session ⇒ Object
- #user ⇒ Object
- #user_id ⇒ Object
Constructor Details
#initialize(env) ⇒ Proxy
Returns a new instance of Proxy.
18 19 20 21 22 23 24 25 |
# File 'lib/clerk/rack_middleware.rb', line 18 def initialize(env) req = Rack::Request.new(env) @token = req.["__session"] @session_id = req.params["_clerk_session_id"] @session = nil @user_id = nil @user = nil end |
Instance Attribute Details
#error ⇒ Object (readonly)
Returns the value of attribute error.
17 18 19 |
# File 'lib/clerk/rack_middleware.rb', line 17 def error @error end |
#session_id ⇒ Object (readonly)
Returns the value of attribute session_id.
17 18 19 |
# File 'lib/clerk/rack_middleware.rb', line 17 def session_id @session_id end |
Instance Method Details
#debug ⇒ Object
48 49 50 51 52 |
# File 'lib/clerk/rack_middleware.rb', line 48 def debug (instance_variables - [:@sdk]).map do |ivar| [ivar.to_s, instance_variable_get(ivar)] end.to_h end |
#session ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/clerk/rack_middleware.rb', line 27 def session return nil if @token.nil? return @session if @session begin @session = fetch_session rescue Errors::Authentication => e @error = e end @session end |
#user ⇒ Object
43 44 45 46 |
# File 'lib/clerk/rack_middleware.rb', line 43 def user return nil if session.nil? @user ||= fetch_user(user_id) end |
#user_id ⇒ Object
39 40 41 |
# File 'lib/clerk/rack_middleware.rb', line 39 def user_id @user_id ||= session.dig("user_id") end |