Commit 621071ca authored by Grzegorz Bizon's avatar Grzegorz Bizon

Refactor and simplify token authenticatable concern

parent 3ee8e019
......@@ -9,21 +9,18 @@ module TokenAuthenticatable
private # rubocop:disable Lint/UselessAccessModifier
def add_authentication_token_field(token_field, options = {})
@token_fields ||= []
unique = options.fetch(:unique, true)
if @token_fields.include?(token_field)
if token_authenticatable_fields.include?(token_field)
raise ArgumentError.new("#{token_field} already configured via add_authentication_token_field")
end
@token_fields << token_field
token_authenticatable_fields.push(token_field)
attr_accessor :cleartext_tokens
strategy = TokenAuthenticatableStrategies::Base
.fabricate(self, token_field, options)
if unique
if options.fetch(:unique, true)
define_singleton_method("find_by_#{token_field}") do |token|
strategy.find_token_authenticatable(token)
end
......@@ -51,5 +48,9 @@ module TokenAuthenticatable
strategy.reset_token!(self)
end
end
def token_authenticatable_fields
@token_authenticatable_fields ||= []
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment