Skip to content

Commit e315c13

Browse files
authored
fix: Username is undefined in email verification link on email change (#8887)
1 parent 3c07fca commit e315c13

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

spec/ValidationAndPasswordsReset.spec.js

+1
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ describe('Custom Pages, Email Verification, Password Reset', () => {
137137
spyOn(emailAdapter, 'sendVerificationEmail').and.callFake(options => {
138138
expect(options.link).not.toBeNull();
139139
expect(options.link).not.toMatch(/token=undefined/);
140+
expect(options.link).not.toMatch(/username=undefined/);
140141
Promise.resolve();
141142
});
142143
const user = new Parse.User();

src/Controllers/UserController.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,8 @@ export class UserController extends AdaptableController {
161161
return;
162162
}
163163
const token = encodeURIComponent(user._email_verify_token);
164-
// We may need to fetch the user in case of update email
164+
// We may need to fetch the user in case of update email; only use the `fetchedUser`
165+
// from this point onwards; do not use the `user` as it may not contain all fields.
165166
const fetchedUser = await this.getUserIfNeeded(user);
166167
let shouldSendEmail = this.config.sendUserEmailVerification;
167168
if (typeof shouldSendEmail === 'function') {
@@ -176,7 +177,7 @@ export class UserController extends AdaptableController {
176177
if (!shouldSendEmail) {
177178
return;
178179
}
179-
const username = encodeURIComponent(user.username);
180+
const username = encodeURIComponent(fetchedUser.username);
180181

181182
const link = buildEmailLink(this.config.verifyEmailURL, username, token, this.config);
182183
const options = {

0 commit comments

Comments
 (0)