lynndylanhurley / devise_token_auth

Token based authentication for Rails JSON APIs. Designed to work with jToker and ng-token-auth.
Do What The F*ck You Want To Public License
3.52k stars 1.14k forks source link

Lockable does not work as expected #1610

Open CodeTectonics opened 9 months ago

CodeTectonics commented 9 months ago

Hello!

Thank you very much for this gem. I use it a lot and it saves me so much time and effort.

I think I have found a bug in the sessions controller, surrounding how it handles the Lockable strategy.

Version devise_token_auth (1.2.2) devise (4.9.2)

Configuration config.lock_strategy = :failed_attempts config.maximum_attempts = 10 config.unlock_keys = [:email] config.unlock_strategy = :time config.unlock_in = 30.minutes config.last_attempt_warning = true

Expected Behaviour I have maximum_attempts set to 10 and last_attempt_warning is set to TRUE, so I expect that:

Actual Behaviour

I was able to bypass this behaviour with the following override to the sessions controller, but this is obviously not an ideal solution:

def render_create_error_bad_credentials
  if @resource.respond_to?(:locked_at) && @resource.failed_attempts == Devise.maximum_attempts - 1
    render_error(401, I18n.t('devise.failure.last_attempt'))
  elsif @resource.respond_to?(:locked_at) && @resource.failed_attempts >= Devise.maximum_attempts
    render_create_error_account_locked
  else
    super
  end
end