# frozen_string_literal: true class User < ApplicationRecord devise :database_authenticatable, :lockable, :recoverable, :rememberable, :trackable, :validatable, :confirmable, :registerable devise :omniauthable, omniauth_providers: %i[reddit google_oauth2 discord] # Note: devise :validatable above adds validations for :email and :password # validates :username, presence: true, length: {maximum: 128} validates :email, confirmation: true def self.from_omniauth(auth) where(provider: auth.provider, uid: auth.uid).first_or_create do |user| user.email = auth.info.email user.password = Devise.friendly_token[0, 20] # Reddit, Google, and Discord both have email verification already user.skip_confirmation! end end end