module ActiveRecord::TokenFor::RelationMethods

def find_by_token_for(purpose, token)

+nil+ if the token is invalid or the record was not found.
Finds a record using a given +token+ for a predefined +purpose+. Returns
def find_by_token_for(purpose, token)
  raise UnknownPrimaryKey.new(self) unless model.primary_key
  model.token_definitions.fetch(purpose).resolve_token(token) { |id| find_by(model.primary_key => [id]) }
end

def find_by_token_for!(purpose, token)

the token is valid but the record was not found.
(e.g. expired, bad format, etc). Raises ActiveRecord::RecordNotFound if
ActiveSupport::MessageVerifier::InvalidSignature if the token is invalid
Finds a record using a given +token+ for a predefined +purpose+. Raises
def find_by_token_for!(purpose, token)
  model.token_definitions.fetch(purpose).resolve_token(token) { |id| find(id) } ||
    (raise ActiveSupport::MessageVerifier::InvalidSignature)
end