fix: Username is undefined in email verification link on email change (#8887)
This commit is contained in:
@@ -137,6 +137,7 @@ describe('Custom Pages, Email Verification, Password Reset', () => {
|
|||||||
spyOn(emailAdapter, 'sendVerificationEmail').and.callFake(options => {
|
spyOn(emailAdapter, 'sendVerificationEmail').and.callFake(options => {
|
||||||
expect(options.link).not.toBeNull();
|
expect(options.link).not.toBeNull();
|
||||||
expect(options.link).not.toMatch(/token=undefined/);
|
expect(options.link).not.toMatch(/token=undefined/);
|
||||||
|
expect(options.link).not.toMatch(/username=undefined/);
|
||||||
Promise.resolve();
|
Promise.resolve();
|
||||||
});
|
});
|
||||||
const user = new Parse.User();
|
const user = new Parse.User();
|
||||||
|
|||||||
@@ -161,7 +161,8 @@ export class UserController extends AdaptableController {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const token = encodeURIComponent(user._email_verify_token);
|
const token = encodeURIComponent(user._email_verify_token);
|
||||||
// We may need to fetch the user in case of update email
|
// We may need to fetch the user in case of update email; only use the `fetchedUser`
|
||||||
|
// from this point onwards; do not use the `user` as it may not contain all fields.
|
||||||
const fetchedUser = await this.getUserIfNeeded(user);
|
const fetchedUser = await this.getUserIfNeeded(user);
|
||||||
let shouldSendEmail = this.config.sendUserEmailVerification;
|
let shouldSendEmail = this.config.sendUserEmailVerification;
|
||||||
if (typeof shouldSendEmail === 'function') {
|
if (typeof shouldSendEmail === 'function') {
|
||||||
@@ -176,7 +177,7 @@ export class UserController extends AdaptableController {
|
|||||||
if (!shouldSendEmail) {
|
if (!shouldSendEmail) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const username = encodeURIComponent(user.username);
|
const username = encodeURIComponent(fetchedUser.username);
|
||||||
|
|
||||||
const link = buildEmailLink(this.config.verifyEmailURL, username, token, this.config);
|
const link = buildEmailLink(this.config.verifyEmailURL, username, token, this.config);
|
||||||
const options = {
|
const options = {
|
||||||
|
|||||||
Reference in New Issue
Block a user