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 }, }) })