Skip to content

Commit 0da0592

Browse files
committed
fix: check user active while login or refresh session
1 parent 2e4cfd6 commit 0da0592

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

src/auth/auth.controller.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,15 @@ import { SignTokenDto } from './dto/sign-token.dto';
3939
import { Authorizer } from './entities/authorizer.entity';
4040
import { SessionWithToken, Token } from './entities/session-with-token.entity';
4141

42+
function checkUserActive(user: UserDocument) {
43+
if (user.active === false) {
44+
throw new ForbiddenException({
45+
code: ErrorCodes.USER_INACTIVE,
46+
message: 'user inactive',
47+
});
48+
}
49+
}
50+
4251
@ApiTags('auth')
4352
@Controller('auth')
4453
export class AuthController {
@@ -85,6 +94,8 @@ export class AuthController {
8594
});
8695
}
8796

97+
checkUserActive(user);
98+
8899
return this.authService.login(user);
89100
}
90101

@@ -194,6 +205,7 @@ export class AuthController {
194205
});
195206
}
196207

208+
checkUserActive(user);
197209
return this.authService.login(user);
198210
}
199211

@@ -220,6 +232,7 @@ export class AuthController {
220232
});
221233
}
222234

235+
checkUserActive(user);
223236
return this.authService.login(user);
224237
}
225238

@@ -242,6 +255,7 @@ export class AuthController {
242255
});
243256
}
244257

258+
checkUserActive(user);
245259
return this.authService.login(user);
246260
}
247261

@@ -446,6 +460,8 @@ export class AuthController {
446460
});
447461
}
448462

463+
checkUserActive(user);
464+
449465
payload.ns = user.ns;
450466
payload.groups = user.groups;
451467
payload.roles = user.roles;

src/constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ export const ErrorCodes = {
44
CAPTCHA_INVALID: 'CAPTCHA_INVALID',
55
TOO_MANY_LOGIN_ATTEMPTS: 'TOO_MANY_LOGIN_ATTEMPTS',
66
USER_NOT_FOUND: 'USER_NOT_FOUND',
7+
USER_INACTIVE: 'USER_INACTIVE',
78
CAPTCHA_NOT_FOUND: 'CAPTCHA_NOT_FOUND',
89
CASTERROR: 'CASTERROR',
910
DUPLICATE: 'DUPLICATE',

0 commit comments

Comments
 (0)