diff --git a/src/shared/modules/user/user.controller.ts b/src/shared/modules/user/user.controller.ts index 311a3b4..13c4291 100644 --- a/src/shared/modules/user/user.controller.ts +++ b/src/shared/modules/user/user.controller.ts @@ -53,6 +53,11 @@ export class UserController extends BaseController { new UploadFileMiddleware(this.configService.get('UPLOAD_DIRECTORY'), 'avatar'), ] }); + this.addRoute({ + path: '/login', + method: HttpMethod.Get, + handler: this.checkAuthenticate, + }); } public async create( @@ -91,4 +96,18 @@ export class UserController extends BaseController { filepath: req.file?.path }); } + + public async checkAuthenticate({ tokenPayload: { email }}: Request, res: Response) { + const foundedUser = await this.userService.findByEmail(email); + + if (! foundedUser) { + throw new HttpError( + StatusCodes.UNAUTHORIZED, + 'Unauthorized', + 'UserController' + ); + } + + this.ok(res, fillDTO(LoggedUserRdo, foundedUser)); + } }