Class: Clearance::RackSession

Inherits:
Object
  • Object
show all
Defined in:
lib/clearance/rack_session.rb

Overview

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

  • maintains the session cookie specified by your Configuration.
  • exposes previously cookied sessions to Clearance and your app at request.env[:clearance], which Authentication#current_user pulls the user from.

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ RackSession

Returns a new instance of RackSession.


14
15
16
# File 'lib/clearance/rack_session.rb', line 14

def initialize(app)
  @app = app
end

Instance Method Details

#call(env) ⇒ Object

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


20
21
22
23
24
25
26
27
28
29
30
# 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 response[1]
  end

  response
end