Skip to content

Commit

Permalink
fix: Parse Server option emailVerifyTokenReuseIfValid: true generat…
Browse files Browse the repository at this point in the history
…es new token on every email verification request (#8885)
  • Loading branch information
mtrezza authored Jan 14, 2024
1 parent 4aba66c commit 0023ce4
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
12 changes: 6 additions & 6 deletions spec/EmailVerificationToken.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -897,7 +897,7 @@ describe('Email Verification Token Expiration: ', () => {
const config = Config.get('test');
const [userBeforeRequest] = await config.database.find('_User', {
username: 'resends_verification_token',
});
}, {}, Auth.maintenance(config));
// store this user before we make our email request
expect(sendVerificationEmailCallCount).toBe(1);
await new Promise(resolve => {
Expand All @@ -923,14 +923,14 @@ describe('Email Verification Token Expiration: ', () => {

const [userAfterRequest] = await config.database.find('_User', {
username: 'resends_verification_token',
});
}, {}, Auth.maintenance(config));

// verify that our token & expiration has been changed for this new request
// Verify that token & expiration haven't been changed for this new request
expect(typeof userAfterRequest).toBe('object');
expect(userBeforeRequest._email_verify_token).toBeDefined();
expect(userBeforeRequest._email_verify_token).toEqual(userAfterRequest._email_verify_token);
expect(userBeforeRequest._email_verify_token_expires_at).toEqual(
userAfterRequest._email_verify_token_expires_at
);
expect(userBeforeRequest._email_verify_token_expires_at).toBeDefined();
expect(userBeforeRequest._email_verify_token_expires_at).toEqual(userAfterRequest._email_verify_token_expires_at);
done();
});

Expand Down
2 changes: 1 addition & 1 deletion src/Controllers/UserController.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ export class UserController extends AdaptableController {
_email_verify_token &&
new Date() < new Date(_email_verify_token_expires_at)
) {
return Promise.resolve();
return Promise.resolve(true);
}
const shouldSend = await this.setEmailVerifyToken(user, {
object: Parse.User.fromJSON(Object.assign({ className: '_User' }, user)),
Expand Down
2 changes: 1 addition & 1 deletion src/Routers/UsersRouter.js
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,7 @@ export class UsersRouter extends ClassesRouter {
);
}

const results = await req.config.database.find('_User', { email: email });
const results = await req.config.database.find('_User', { email: email }, {}, Auth.maintenance(req.config));
if (!results.length || results.length < 1) {
throw new Parse.Error(Parse.Error.EMAIL_NOT_FOUND, `No user found with email ${email}`);
}
Expand Down

0 comments on commit 0023ce4

Please sign in to comment.