Skip to content

Instantly share code, notes, and snippets.

@Carpetfizz
Last active December 30, 2016 01:17
Show Gist options
  • Save Carpetfizz/2b68c3eee6b6485065df7c4644766fdf to your computer and use it in GitHub Desktop.
Save Carpetfizz/2b68c3eee6b6485065df7c4644766fdf to your computer and use it in GitHub Desktop.
class User < ApplicationRecord
def self.find_or_create_from_auth_hash(auth)
where(provider: auth.provider, uid: auth.uid).first_or_initialize.tap do |user|
user.provider = auth.provider
user.uid = auth.uid
user.first_name = auth.info.first_name
user.last_name = auth.info.last_name
user.email = auth.info.email
user.picture = auth.info.image
user.save!
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment