I have a method in my user model (which uses devise and confirmable) called new_with_session as required by Omniauth + Devise (https://github.com/plataformatec/devise/wiki/OmniAuth:-Overview):
def self.new_with_session(params, session)
super.tap do |user|
if data = session["devise.facebook_data"] && session["devise.facebook_data"]["extra"]["raw_info"] || session["devise.google_data"] && session["devise.google_data"]["extra"]["raw_info"]
user.email = data["email"]
end
end
end
Users are allowed to sign in using either Google or Facebook, and I'm using this line to save the right user.email:
if data = session["devise.facebook_data"] && session["devise.facebook_data"]["extra"]["raw_info"] || session["devise.google_data"] && session["devise.google_data"]["extra"]["raw_info"]
but I don't think is the right way, so...
user.email than using the || operator?new_with_session? If so, why? new_with_session is used in build_resource. This is used with registerable (user regsitration forms).
This is only useful when your Facebook/Omniauth session already exists and you want to prefill your Registration form with some data from omniauth. (assuming you didn't already create the account automatically on callback)
# Build a devise resource passing in the session. Useful to move
# temporary session data to the newly created user.
def build_resource(hash=nil)
hash ||= params[resource_name] || {}
self.resource = resource_class.new_with_session(hash, session)
end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With