Module: DeviseMultipleTokenAuth::ActiveRecord::Base::ClassMethods

Defined in:
lib/devise_multiple_token_auth/active_record/base.rb

Instance Method Summary collapse

Instance Method Details

#devise_token_authenticatableObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/devise_multiple_token_auth/active_record/base.rb', line 10

def devise_token_authenticatable
  class_eval do
    has_many :devices, class_name: "DeviseMultipleTokenAuth::Device", dependent: :destroy
    def create_device
      DeviseMultipleTokenAuth::Device.destroy_expired
      new_device = Device.new
      new_device.user = self
      new_device.auth_token = SecureRandom.hex
      new_device.expires_at = (DeviseMultipleTokenAuth.device_expires_in_days || 14).days.from_now
      new_device.save!
      return new_device
    end
  end
end