From d368ae9af06a2b6944234c4dc9fac7a7b7e59e71 Mon Sep 17 00:00:00 2001 From: MohammadHMazarei Date: Mon, 23 Dec 2024 23:10:35 +0330 Subject: [PATCH] ADD: login handler --- components/user/userController.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/components/user/userController.js b/components/user/userController.js index 47ecb6f..c4cff2c 100644 --- a/components/user/userController.js +++ b/components/user/userController.js @@ -14,10 +14,13 @@ exports.signup = catchAsync(async (req, res, next) => { }) exports.loginUser = catchAsync(async (req, res, next) => { - const user = await userService.loginUser(req.body.rawPassword) + const { email, password } = req.body + const { token, user } = await userService.loginUser(email, password) const maxAge = 60 * 60 * 24 * 90 - res.cookie('raw-password', user.rawPassword, { + res.setHeader('Authorization', `Bearer ${token}`) + + res.cookie('belonging_token', token, { httpOnly: true, maxAge: maxAge * 1000, path: '/', @@ -25,7 +28,7 @@ exports.loginUser = catchAsync(async (req, res, next) => { res.status(200).json({ status: 'success', - data: user, + data: { user, token }, }) })