Module: Croods::Resource::Authentication

Defined in:
lib/croods/resource/authentication.rb

Constant Summary collapse

OPTIONS =
i[
  database_authenticatable registerable recoverable rememberable
  trackable validatable
].freeze
ATTRIBUTES =
i[
  allow_password_change confirmation_sent_at confirmation_token
  encrypted_password confirmed_at provider uid remember_created_at
  reset_password_sent_at reset_password_token tokens unconfirmed_email
     
  
].freeze

Instance Method Summary collapse

Instance Method Details

#add_model_authentication(*options) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/croods/resource/authentication.rb', line 31

def add_model_authentication(*options)
  extend_model do
    before_create do
      self.uid = email unless uid.present?
    end

    extend Devise::Models

    devise_options = options.empty? ? OPTIONS : options
    devise(*devise_options)

    include DeviseTokenAuth::Concerns::User
  end
end

#use_for_authentication!(*options) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
# File 'lib/croods/resource/authentication.rb', line 19

def use_for_authentication!(*options)
  add_model_authentication(*options)

  skip_attributes(*ATTRIBUTES)
  skip_attribute(Croods.tenant_attribute) if Croods.multi_tenancy?

  request do
    add_attribute :password, :string, null: false
    skip_attribute :admin
  end
end