Module: IntercomRails::ShutdownHelper

Defined in:
lib/intercom-rails/shutdown_helper.rb

Class Method Summary collapse

Class Method Details

.intercom_shutdown(session, cookies, domain = nil) ⇒ Object



24
25
26
27
28
29
# File 'lib/intercom-rails/shutdown_helper.rb', line 24

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

.intercom_shutdown_helper(cookies, domain = nil) ⇒ Object

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



6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/intercom-rails/shutdown_helper.rb', line 6

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

.prepare_intercom_shutdown(session) ⇒ Object



20
21
22
# File 'lib/intercom-rails/shutdown_helper.rb', line 20

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