class Userbin::Request::Middleware::SessionToken

Sends the active session token in a header, and extracts the returned session token and sets it locally.

Public Instance Methods

call(env) click to toggle source
# File lib/userbin/request.rb, line 80
def call(env)
  userbin = RequestStore.store[:userbin]
  return @app.call(env) unless userbin

  # get the session token from our local store
  if userbin.session_token
    env[:request_headers]['X-Userbin-Session-Token'] =
      userbin.session_token.to_s
  end

  # call the API
  response = @app.call(env)

  # update the local store with the updated session token
  token = response.env.response_headers['x-userbin-set-session-token']
  userbin.session_token = token if token

  response
end