Skip to content

Commit 20ceeb1

Browse files
fix(auth): add block scope to switch case clauses to prevent variable leaking
Switch statements in JS/TS share scope across case clauses, which can cause variable declarations to leak or conflict. Wrapped MikroORM and TypeORM case bodies in their own blocks ({}) so declarations are lexically scoped to each case.
1 parent 2002a11 commit 20ceeb1

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

packages/core/src/lib/auth/auth.service.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -875,7 +875,7 @@ export class AuthService extends SocialAuthService {
875875
let user: User;
876876

877877
switch (this.ormType) {
878-
case MultiORMEnum.MikroORM:
878+
case MultiORMEnum.MikroORM: {
879879
const { where, mikroOptions } = parseTypeORMFindToMikroOrm<User>({
880880
where: {
881881
id: userId,
@@ -888,8 +888,9 @@ export class AuthService extends SocialAuthService {
888888
});
889889
user = (await this.mikroOrmUserRepository.findOne(where, mikroOptions)) as User;
890890
break;
891+
}
891892

892-
case MultiORMEnum.TypeORM:
893+
case MultiORMEnum.TypeORM: {
893894
user = await this.typeOrmUserRepository.findOne({
894895
where: {
895896
id: userId,
@@ -901,6 +902,7 @@ export class AuthService extends SocialAuthService {
901902
order: { createdAt: 'DESC' }
902903
});
903904
break;
905+
}
904906

905907
default:
906908
throw new Error(`Method not implemented for ORM type: ${this.ormType}`);
@@ -1634,7 +1636,7 @@ export class AuthService extends SocialAuthService {
16341636
let user: User;
16351637

16361638
switch (this.ormType) {
1637-
case MultiORMEnum.MikroORM:
1639+
case MultiORMEnum.MikroORM: {
16381640
const { where, mikroOptions } = parseTypeORMFindToMikroOrm<User>({
16391641
where: {
16401642
id: currentUser.id,
@@ -1646,8 +1648,9 @@ export class AuthService extends SocialAuthService {
16461648
});
16471649
user = (await this.mikroOrmUserRepository.findOne(where, mikroOptions)) as User;
16481650
break;
1651+
}
16491652

1650-
case MultiORMEnum.TypeORM:
1653+
case MultiORMEnum.TypeORM: {
16511654
user = await this.typeOrmUserRepository.findOne({
16521655
where: {
16531656
id: currentUser.id,
@@ -1658,6 +1661,7 @@ export class AuthService extends SocialAuthService {
16581661
relations: { role: { rolePermissions: true } }
16591662
});
16601663
break;
1664+
}
16611665

16621666
default:
16631667
throw new Error(`Method not implemented for ORM type: ${this.ormType}`);

0 commit comments

Comments
 (0)