Skip to content

Commit 43684f2

Browse files
authored
Update one_time_password.rb (#67)
When using auto_increment it wouldn't save the model so when I had a different instance of the user the counter would never match.
1 parent 7ac1fab commit 43684f2

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

lib/active_model/one_time_password.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ def authenticate_otp(code, options = {})
4949
result = hotp.verify(code, otp_counter)
5050
if result && options[:auto_increment]
5151
self.otp_counter += 1
52-
save if respond_to?(:new_record?) && !new_record?
52+
save if respond_to?(:changed?) && !new_record?
5353
end
5454
result
5555
else
@@ -66,7 +66,7 @@ def otp_code(options = {})
6666
if otp_counter_based
6767
if options[:auto_increment]
6868
self.otp_counter += 1
69-
save if respond_to?(:new_record?) && !new_record?
69+
save if respond_to?(:changed?) && !new_record?
7070
end
7171
ROTP::HOTP.new(otp_column, digits: otp_digits).at(self.otp_counter)
7272
else

0 commit comments

Comments
 (0)