class Clearance::RackSession

Rack middleware that manages the Clearance {Session}. This middleware is automatically mounted by the Clearance {Engine}.

@see Session @see Configuration#cookie_name

Public Class Methods

new(app) click to toggle source
# File lib/clearance/rack_session.rb, line 14
def initialize(app)
  @app = app
end

Public Instance Methods

call(env) click to toggle source

Reads previously existing sessions from a cookie and maintains the cookie on each response.

# File lib/clearance/rack_session.rb, line 20
def call(env)
  session = Clearance::Session.new(env)
  env[:clearance] = session
  response = @app.call(env)

  if session.authentication_successful?
    session.add_cookie_to_headers
  end

  response
end