-
-
Save hassox/7b63df9506edf43f85dd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Warden::SessionSerializer | |
def serialize(record) | |
case record.class | |
when TrueClass, FalseClass | |
[record.class.name, record] | |
else | |
[record.class.name, record.to_key, record.authenticatable_salt] | |
end | |
end | |
def deserialize(keys) | |
if keys.size == 2 && ['TrueClass', 'FalseClass'].includes?(keys.first) | |
return keys.last | |
end | |
if keys.size == 2 | |
raise "Devise changed how it stores objects in session. If you are seeing this message, " << | |
"you can fix it by changing one character in your secret_token or cleaning up your " << | |
"database sessions if you are using a db store." | |
end | |
klass, id, salt = keys | |
begin | |
record = ActiveSupport::Inflector.constantize(klass).to_adapter.get(id) | |
record if record && record.authenticatable_salt == salt | |
rescue NameError => e | |
if e.message =~ /uninitialized constant/ | |
Rails.logger.debug "[Devise] Trying to deserialize invalid class #{klass}" | |
nil | |
else | |
raise | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment