Confirmation token invalid shown if used twice misleading
I just had a new user tell me that it wasn't letting him confirm his email.
When I checked, the email was already confirmed. Perhaps the page was loaded twice or something, and after the first use, the token is no longer valid.
I suggest that after confirming, the token is left in the database, so that the page can tell the user that it has already been confirmed.
I believe no extra DB columns are required, because the confirmed_at field is used to check whether an account is confirmed, and unconfirmed_email is used for whether any reconfirmation is required.
I believe this has been fixed in latest Devise versions. Which Devise version are you using?
devise (3.2.2)
Ok, I was wrong, it seems we do not have this feature. Its addition is probably welcome!
Just read some of the code. Would taking out the line setting the token to nil make it work? Once set to nil, the token cannot be looked up anymore. So you never check "pending_any_confirmation" again.
def confirm!(args={})
pending_any_confirmation do
...
self.confirmation_token = nil # take this line out???
...
end
end
def pending_any_confirmation
if (!confirmed? || pending_reconfirmation?)
yield
else
self.errors.add(:email, :already_confirmed)
false
end
end
That sounds like it! And a test case too. :)