fix: Username is undefined in email verification link on email change (#8887)

This commit is contained in:
Manuel
2024-01-15 00:47:03 +01:00
committed by GitHub
parent 3c07fcada6
commit e315c137bf
2 changed files with 4 additions and 2 deletions

View File

@@ -137,6 +137,7 @@ describe('Custom Pages, Email Verification, Password Reset', () => {
spyOn(emailAdapter, 'sendVerificationEmail').and.callFake(options => {
expect(options.link).not.toBeNull();
expect(options.link).not.toMatch(/token=undefined/);
expect(options.link).not.toMatch(/username=undefined/);
Promise.resolve();
});
const user = new Parse.User();

View File

@@ -161,7 +161,8 @@ export class UserController extends AdaptableController {
return;
}
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);
let shouldSendEmail = this.config.sendUserEmailVerification;
if (typeof shouldSendEmail === 'function') {
@@ -176,7 +177,7 @@ export class UserController extends AdaptableController {
if (!shouldSendEmail) {
return;
}
const username = encodeURIComponent(user.username);
const username = encodeURIComponent(fetchedUser.username);
const link = buildEmailLink(this.config.verifyEmailURL, username, token, this.config);
const options = {