Skip to content

Instantly share code, notes, and snippets.

@ParthivPatel-BTC
Created September 10, 2019 02:01
Show Gist options
  • Save ParthivPatel-BTC/a2f50f5230d8358cdbbce86d72dc90c7 to your computer and use it in GitHub Desktop.
Save ParthivPatel-BTC/a2f50f5230d8358cdbbce86d72dc90c7 to your computer and use it in GitHub Desktop.
OAuthUserModel
class User < ApplicationRecord
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable, :trackable and :omniauthable
devise :omniauthable, :omniauth_providers => [:google_oauth2]
has_many :tasks
def self.from_omniauth(access_token)
data = access_token.info
user = User.where(:email => data["email"]).first
unless user
user = User.create(
name: data["name"],
email: data["email"],
encrypted_password: Devise.friendly_token[0,20]
)
end
user
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment