ADD: login handler

This commit is contained in:
MohammadHMazarei
2024-12-23 23:10:35 +03:30
parent 3fe2377ce3
commit d368ae9af0
+6 -3
View File
@@ -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 },
})
})