Skip to content

Instantly share code, notes, and snippets.

@NicholusMuwonge
Created October 24, 2020 14:28
Show Gist options
  • Save NicholusMuwonge/38f669a98f086e34277b7bf2dc23e0bb to your computer and use it in GitHub Desktop.
Save NicholusMuwonge/38f669a98f086e34277b7bf2dc23e0bb to your computer and use it in GitHub Desktop.
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