Sha256: d8587d62d3c9ececf3e764e8b9aea0c4f51d3382475fceff9e4fb592e90b40b3

Contents?: true

Size: 1.44 KB

Versions: 8

Compression:

Stored size: 1.44 KB

Contents

module IntercomRails
  module ShutdownHelper
    # This helper allows to erase cookies when a user log out of an application
    # It is recommanded to call this function every time a user log out of your application
    # Do not use before a redirect_to because it will not clear the cookies on a redirection
    def self.intercom_shutdown_helper(cookies, domain = nil)
      nil_session = { value: nil, expires: 1.day.ago }
      nil_session = nil_session.merge(domain: domain) unless domain.nil? || domain == 'localhost'

      if (cookies.is_a?(ActionDispatch::Cookies::CookieJar))
        cookies["intercom-session-#{IntercomRails.config.app_id}"] = nil_session
      else
        controller = cookies
        Rails.logger.info("Warning: IntercomRails::ShutdownHelper.intercom_shutdown_helper takes an instance of ActionDispatch::Cookies::CookieJar as an argument since v0.2.34. Passing a controller is depreciated. See https://github.com/intercom/intercom-rails#shutdown for more details.")
        controller.response.delete_cookie("intercom-session-#{IntercomRails.config.app_id}", nil_session)
      end
    rescue
    end

    def self.prepare_intercom_shutdown(session)
      session[:perform_intercom_shutdown] = true
    end

    def self.intercom_shutdown(session, cookies, domain = nil)
      if session[:perform_intercom_shutdown]
        session.delete(:perform_intercom_shutdown)
        intercom_shutdown_helper(cookies, domain)
      end
    end

  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
intercom-rails-1.0.6 lib/intercom-rails/shutdown_helper.rb
intercom-rails-1.0.5 lib/intercom-rails/shutdown_helper.rb
intercom-rails-1.0.4 lib/intercom-rails/shutdown_helper.rb
intercom-rails-1.0.1 lib/intercom-rails/shutdown_helper.rb
intercom-rails-1.0.0 lib/intercom-rails/shutdown_helper.rb
intercom-rails-0.4.2 lib/intercom-rails/shutdown_helper.rb
intercom-rails-0.4.1 lib/intercom-rails/shutdown_helper.rb
intercom-rails-0.4.0 lib/intercom-rails/shutdown_helper.rb