mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-16 12:50:38 +00:00
fix: should retrieve user inactive error in login response API.
fix: prevent from delete or inactivate the current authorized user.
This commit is contained in:
@@ -14,11 +14,19 @@ const attachCurrentUser = async (req: Request, res: Response, next: Function) =>
|
||||
try {
|
||||
Logger.info('[attach_user_middleware] finding system user by id.');
|
||||
const user = await systemUserRepository.getById(req.token.id);
|
||||
console.log(user);
|
||||
|
||||
if (!user) {
|
||||
Logger.info('[attach_user_middleware] the system user not found.');
|
||||
return res.boom.unauthorized();
|
||||
}
|
||||
if (!user.active) {
|
||||
Logger.info('[attach_user_middleware] the system user not found.');
|
||||
return res.boom.badRequest(
|
||||
'The authorized user is inactivated.',
|
||||
{ errors: [{ type: 'USER_INACTIVE', code: 100, }] },
|
||||
);
|
||||
}
|
||||
// Delete password property from user object.
|
||||
Reflect.deleteProperty(user, 'password');
|
||||
req.user = user;
|
||||
|
||||
Reference in New Issue
Block a user