docbrown/app/controllers/sessions_controller.rb
rhymes ffd0ce790b
[deploy] Session cookie domain hotfix for login and logout (#10169)
* Session cookie domain hotfix for login and logout

* Add timefame for removal
2020-09-03 10:45:35 -04:00

34 lines
873 B
Ruby

class SessionsController < Devise::SessionsController
def create
delete_legacy_cookie
super
end
def destroy
# Let's say goodbye to all the cookies when someone signs out.
cookies.clear(domain: cookie_domain)
delete_legacy_cookie
super
end
private
def cookie_domain
Rails.env.production? ? ApplicationConfig["APP_DOMAIN"] : nil
end
# NOTE: this code is a hotfix, and shall be removed soon (around 2 weeks from deployment)
def delete_legacy_cookie
domain = cookie_domain
return unless domain&.starts_with?(".")
# Deleting the session cookie with the previous app domain, the one without the leading dot.
# This should fix the double cookie scenario
domain_without_leading_dot = domain.gsub(/\A./, "")
cookies.delete(ApplicationConfig["SESSION_KEY"], domain: domain_without_leading_dot)
end
end