feat(validators): add check for non-existent userId
- The `UserGuard` now checks whether the `userId` extracted from the token exists. - If the `userId` does not exist, an error is logged and a response with the 'Unauthorized' status is returned. Signed-off-by: Mathis <yidhra@tuta.io>
This commit is contained in:
parent
a74731a49e
commit
3231f916f8
@ -27,6 +27,10 @@ async function UserGuard(req: Request, res: Response, next: NextFunction) {
|
||||
if (token) {
|
||||
// @ts-ignore
|
||||
const userId = token.sub;
|
||||
if (!userId) {
|
||||
logger.error(USER_NOT_EXIST);
|
||||
return res.status(UNAUTHORIZED).json({message: USER_NOT_EXIST});
|
||||
}
|
||||
const user= await MySqlService.User.getById(DbHandler, userId);
|
||||
if (user) {
|
||||
logger.info(`An user do a request. (${user?.username})`)
|
||||
|
Loading…
x
Reference in New Issue
Block a user