-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Confirming an already confirmed user -- still not quite working. #1123
Comments
@lynndylanhurley, @MaicolBen, @zachfeldman, @dks17, @KelseyDH, thoughts? ☝️ |
Agreed with that, it's awful. And agreed with your planned changes. If with I prefer e2e tests like rspec request tests because they don't depend on internals, but it's hard to migrate the current test suite. |
Question. Is the life cycle of the current version coming at the end and to go further new version of this gem should be released with reconsidering workflow, rspec, resolved issues (and, of course new ones) and etc? |
We aren't planning to change the current workflow, the next big milestone is #990 and it should work with the current workflow. If you have in mind a different workflow, open an issue and we discuss it. |
To maintainers - thank you all for the gem and efforts to keep it up! I really like how simple devise controller looks using I just came here to say that currently if the user was already confirmed we are returning an expired token with |
I am dealing with confirmation in my projects right now, and have two comments:
The first item may be an unrelated bug and if so can be disconsidered. |
+1 I just encountered this issue. I feel like more gracefully handling when a confirmed user clicks the confirm email link a second time would be a significant improvement. |
meet this issue. I have a feeling that both devise and devise_token_auth are no longer actively maintained. |
Resolved by #1557 |
NOTE: Much of this has been referenced before in several different Issues and PRs, which I will attempt to link to. If I've left any out, I apologize in advance.
Although it appears that this was first noted in either #410 or #519, and eventually merged in #1001, the current behavior is still not great.
After confirming a user's email address, I can continue to click the confirmation link (i.e. make GET requests to the
/auth/confirmations
endpoint, triggering thedevise_token_auth/confirmations#show
action). It seems that the current behavior will generate a new auth token for the user, and redirect to the successful confirmation URL (either from the params if present, or theDeviseTokenAuth.default_confirm_success_url
).As pointed out in #1064, #1067, and #1075, when the new token is created, it conditionally adds a expiration if the user has signed in (the
:sign_in_count
attribute), which creates a dependency on:trackable
. And while #1064 + #1061 effectively uncouple the dependency, the result is that if:trackable
is not included, then no expiration is set on the token! What-the-huh!!?The confirmation process should happen in a consistent manner, regardless of the presence of the
:trackable
module. A review of the Devise internals shows that checking if a user has signed in (i.e.@resource.has_attribute?(:sign_in_count) && @resource.sign_in_count > 0
) is not an indicator of the user having been confirmed! Rather, it is the presence of a timestamp in the:confirmed_at
attribute that indicates if a user has confirmed their account. (See:Devise::Models::Confirmable#confirm
andDevise::Models::Confirmable#confirmed?
)Furthermore, the
Devise::ConfirmationsController#show
action simply and concisely checks for the presence of validation errors on the user resource, as it handles checking for already confirmed users at the model level. (TheDevise::Models::Confirmable#confirm
method sets errors on the user's:email
attribute, if that user has already been confirmed).We're already using the same
Devise::Models::Confirmable::ClassMethods#confirm_by_token
method in:devise_token_auth/app/controllers/devise_token_auth/confirmations_controller.rb
Lines 3 to 4 in 38d27cf
Therefore, it shouldn't really be necessary to check for specific attributes (or their values) on the user instance (e.g.
:sign_in_count
,:confirmed_at
, etc...); just check for errors on the returned user instance like theDevise::ConfirmationsController#show
action does. The question is, what does a failure response from the controller action look like? It currently is just a 404Not Found
, but presumably it would callDeviseTokenAuth::ApplicationController#render_error
, passing in the relevant validation errors where appropriate.Lastly, it seems like the tests in the
confirmations_controller_test.rb
not actually test most model level attributes; instead the tests should assert that various requests (each in known states) lead to the correct set of controller responses given those states.Specifically, the tests for
:trackable
attributes should not exist at all here:devise_token_auth/test/controllers/devise_token_auth/confirmations_controller_test.rb
Lines 55 to 65 in 38d27cf
And additional tests are needed to check the various possible validation errors on the user that could happen when calling
Devise::Models::Confirmable::ClassMethods#confirm_by_token
.I do intend on making a PR for all this, but I'm hoping to collect some feedback in the meantime.
The text was updated successfully, but these errors were encountered: