-
-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Ability to expire email verify token #2216
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
Ability to expire email verify token #2216
Conversation
@flovilmart |
Just restarted it :) |
@flovilmart |
Not yet, I'll do it before the weekend
|
I think we should only add 1 new setting, the |
username: username, | ||
_email_verify_token: token | ||
}, {emailVerified: true}).then(document => { | ||
if (!document) { | ||
}, {limit: 1}).then(results => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of this, I'd suggest adding a condition to the update that the current time must be before the expiry date, then if that fails you can do a query for the object to find the reason why it failed. That way the happy path requires one less query, and it will be less racy.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good. I will incorporate your suggestion. I will add _email_verify_expires_at
checking in the query for the update
statement.
btw: You may know this already...if there is a failure then we redirect the user to the invalid_link
. We currently don't send the error message/failure reason back with the invalid_link
. If there is a request to send the failure reason then I will take a shot at it in another PR.
@flovilmart Are you ok if I change the code to use only one setting If you are ok then I will:
Please let me know either way :) |
IM all good with that :) |
@cherukumilli updated the pull request. |
3 similar comments
@cherukumilli updated the pull request. |
@cherukumilli updated the pull request. |
@cherukumilli updated the pull request. |
@@ -151,6 +151,11 @@ export default { | |||
help: "Prevent user from login if email is not verified and PARSE_SERVER_VERIFY_USER_EMAILS is true, defaults to false", | |||
action: booleanParser | |||
}, | |||
"emailVerifyTokenValidityDuration": { | |||
env: "PARSE_EMAIL_VERIFY_TOKEN_VALIDITY_DURATION", | |||
help: "Email verification token validity duration, defaults to 1 year", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doc needs update
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated doc
@cherukumilli updated the pull request. |
Cool. I think is solid, but because it involves a new public API I'd like to give it a few more days for comments. We maya want to eg. discuss what happens to existing tokens when people enable this for the first time. Another alternative would be to store the time the token was created rather than the time it expires, then if someone shortens the validity duration, existing tokens will be valid for the length of the new duration, not the old one. Session expiry doesn't work that way, though, so it might be confusing. |
@drew-gross I wonder if the following is a better solution than this PR:
Please let me know if you see any gaps in the logic above. |
Hmm, I missed the context about deleting users who have not verified their email. I don't think thats a great idea, I think a better plan would be to resend the verification email (which can be done today by setting the email on the user. It will resend the email even if it's the same address). Then people could recover their account if they delete the original verification email. That plan for doing user cleanup without a new public API seems solid, but adding expiry as a new API seems like it would be useful as well. |
I didn't know that setting the email on the user will trigger another verification email. Based on the feedback, I will add the following new test cases:
|
@cherukumilli updated the pull request. |
1 similar comment
@cherukumilli updated the pull request. |
Code looks super solid and very well tested. One more api decision which we should consider is whether to let the client see this field, and/or edit it via regular Parse Queries, or strip it and not allow the client to see it. If we decided we do want to allow the client to see/edit this field, we can merge as is. |
IMHO we should not (same as emailVerified) |
@drew-gross If it is then it is hidden. I made it to mimic the |
I noticed in the tests you are using |
Let me fix that and push another update with a test case to ensure that the client cannot see the |
@cherukumilli updated the pull request. |
@cherukumilli updated the pull request. |
@flovilmart |
there you have it :) |
user.fetch() | ||
.then(() => { | ||
expect(user.get('emailVerified')).toEqual(false); | ||
expect(typeof user.get('_email_verify_token_expires_at')).toBe('undefined'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
@cherukumilli just 1 micro nit on the environment variable otherwise that looks more than awesome |
@cherukumilli updated the pull request. |
Awesome, just a note for the future, there is no need to squash your commits as we squash them upon merging :) |
Thanks. I will not squash them going forward. can you please re-run the build again? |
@drew-gross I'll let you merge as you reviewed the code more extensively |
Looks awesome to me. So many tests ❤️ |
Fixes #2198
Notes for this PR:
emailVerifyTokenValidityDuration
(not set by default)if
emailVerifyTokenValidityDuration
is set to a number greater than0
andverifyUserEmails
is set totrue
then_email_verify_token_expires_at
in the _User class along with the_email_verify_token
atSignUp
time_email_verify_token_expires_at
=currentTime
+emailVerifyTokenValidityDuration
BEFORE
_email_verify_token_expires_at
thenemailVerified
totrue
in theUser
class (this code is already in place)_email_verify_token
and_email_verify_token_expires_at
fields for this user (new code)email verification
successfully but clicks on the link for second time then return an error message (i.e., fail gracefully)AFTER
the_email_verify_token_expires_at
thenemail verification token expired.
_User
class with expired verify email tokens is out of scope for this PR. Clean up should be handled by a job outside the normal auth flow.Documentation updates
Updated README.md with the following:
Testing
Added 10 new test cases in a new spec file
EmailVerificationToken.spec.js