Created
October 24, 2020 14:28
-
-
Save NicholusMuwonge/38f669a98f086e34277b7bf2dc23e0bb to your computer and use it in GitHub Desktop.
This file contains hidden or 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 User < ApplicationRecord | |
# Include default devise modules. Others available are: | |
# :confirmable, :lockable, :timeoutable, :trackable and :omniauthable | |
# for omniauth token if its what you're using for your api, I am assuming its what you're using in this tutorial | |
include DeviseTokenAuth::Concerns::User | |
devise :database_authenticatable, :registerable, | |
:recoverable, :rememberable, :validatable, | |
:confirmable, :omniauthable, | |
omniauth_providers: %i[google_oauth2 facebook] # add omniauthable field and add the providers under omniauth_providers | |
def self.signin_or_create_from_provider(provider_data) | |
where(provider: provider_data[:provider], uid: provider_data[:uid]).first_or_create do |user| | |
user.email = provider_data[:info][:email] | |
user.password = Devise.friendly_token[0, 20] | |
user.skip_confirmation! # when you signup a new user, you can decide to skip confirmation | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment