Skip to content

Commit

Permalink
fix(core): Fix issue updating customer email address when no native auth
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelbromley committed Jun 30, 2023
1 parent 86853ec commit 79aab66
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
6 changes: 5 additions & 1 deletion packages/core/src/service/services/customer.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,11 @@ export class CustomerService {
return new EmailAddressConflictAdminError();
}

await this.userService.changeNativeIdentifier(ctx, customer.user.id, input.emailAddress);
await this.userService.changeUserAndNativeIdentifier(
ctx,
customer.user.id,
input.emailAddress,
);
}
}
}
Expand Down
19 changes: 8 additions & 11 deletions packages/core/src/service/services/user.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -307,26 +307,23 @@ export class UserService {
* Changes the User identifier without an email verification step, so this should be only used when
* an Administrator is setting a new email address.
*/
async changeNativeIdentifier(ctx: RequestContext, userId: ID, newIdentifier: string) {
async changeUserAndNativeIdentifier(ctx: RequestContext, userId: ID, newIdentifier: string) {
const user = await this.getUserById(ctx, userId);
if (!user) {
return;
}
const nativeAuthMethod = user.authenticationMethods.find(
(m): m is NativeAuthenticationMethod => m instanceof NativeAuthenticationMethod,
);
if (!nativeAuthMethod) {
// If the NativeAuthenticationMethod is not configured, then
// there is nothing to do.
return;
if (nativeAuthMethod) {
nativeAuthMethod.identifier = newIdentifier;
nativeAuthMethod.identifierChangeToken = null;
nativeAuthMethod.pendingIdentifier = null;
await this.connection
.getRepository(ctx, NativeAuthenticationMethod)
.save(nativeAuthMethod, { reload: false });
}
user.identifier = newIdentifier;
nativeAuthMethod.identifier = newIdentifier;
nativeAuthMethod.identifierChangeToken = null;
nativeAuthMethod.pendingIdentifier = null;
await this.connection
.getRepository(ctx, NativeAuthenticationMethod)
.save(nativeAuthMethod, { reload: false });
await this.connection.getRepository(ctx, User).save(user, { reload: false });
}

Expand Down

0 comments on commit 79aab66

Please sign in to comment.