Sha256: 43dc79547df662a263f7524e8fd70da3d9576f05f69ef42347e6b6e659438fb9

Contents?: true

Size: 887 Bytes

Versions: 4

Compression:

Stored size: 887 Bytes

Contents

module Clearance
  # 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.
  #
  # @see Session
  # @see Configuration#cookie_name
  #
  class RackSession
    def initialize(app)
      @app = app
    end

    # Reads previously existing sessions from a cookie and maintains the cookie
    # on each response.
    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
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
clearance-2.3.0 lib/clearance/rack_session.rb
clearance-2.2.1 lib/clearance/rack_session.rb
clearance-2.2.0 lib/clearance/rack_session.rb
clearance-2.1.0 lib/clearance/rack_session.rb