Skip to content

Commit

Permalink
fix(core): Delete user sessions & token upon user-deletion (#2241)
Browse files Browse the repository at this point in the history
This applies to both admins and regular users.
  • Loading branch information
DanielBiegler authored Jul 4, 2023
1 parent 3fb7bb9 commit b989607
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions packages/core/src/service/services/user.service.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Injectable } from '@nestjs/common';
import { ModuleRef } from '@nestjs/core';
import { VerifyCustomerAccountResult } from '@vendure/common/lib/generated-shop-types';
import { ID } from '@vendure/common/lib/shared-types';

Expand Down Expand Up @@ -41,6 +42,7 @@ export class UserService {
private roleService: RoleService,
private passwordCipher: PasswordCipher,
private verificationTokenGenerator: VerificationTokenGenerator,
private moduleRef: ModuleRef,
) {}

async getUserById(ctx: RequestContext, userId: ID): Promise<User | undefined> {
Expand Down Expand Up @@ -170,6 +172,10 @@ export class UserService {
}

async softDelete(ctx: RequestContext, userId: ID) {
// Dynamic import to avoid the circular dependency of SessionService
await this.moduleRef
.get((await import('./session.service.js')).SessionService)
.deleteSessionsByUser(ctx, new User({ id: userId }));
await this.connection.getEntityOrThrow(ctx, User, userId);
await this.connection.getRepository(ctx, User).update({ id: userId }, { deletedAt: new Date() });
}
Expand Down

0 comments on commit b989607

Please sign in to comment.