ADD: login handler
This commit is contained in:
@@ -14,10 +14,13 @@ exports.signup = catchAsync(async (req, res, next) => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
exports.loginUser = 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
|
const maxAge = 60 * 60 * 24 * 90
|
||||||
|
|
||||||
res.cookie('raw-password', user.rawPassword, {
|
res.setHeader('Authorization', `Bearer ${token}`)
|
||||||
|
|
||||||
|
res.cookie('belonging_token', token, {
|
||||||
httpOnly: true,
|
httpOnly: true,
|
||||||
maxAge: maxAge * 1000,
|
maxAge: maxAge * 1000,
|
||||||
path: '/',
|
path: '/',
|
||||||
@@ -25,7 +28,7 @@ exports.loginUser = catchAsync(async (req, res, next) => {
|
|||||||
|
|
||||||
res.status(200).json({
|
res.status(200).json({
|
||||||
status: 'success',
|
status: 'success',
|
||||||
data: user,
|
data: { user, token },
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user