feat(user): 添加用户登出功能
- 在 userController.js 中实现 logout 方法,销毁用户会话 - 在 routes/index.js 中添加 logout 路由
This commit is contained in:
parent
8741389ef5
commit
321a2566de
@ -107,6 +107,20 @@ exports.login = [
|
|||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
||||||
|
exports.logout = async (req, res) => {
|
||||||
|
try {
|
||||||
|
req.session.destroy()
|
||||||
|
return FetchResult.formatResult(res, HTTP_STATUS.OK, messages.user.logout)
|
||||||
|
} catch (err) {
|
||||||
|
logger('Error logging out: ', err)
|
||||||
|
return FetchResult.formatResult(
|
||||||
|
res,
|
||||||
|
HTTP_STATUS.INTERNAL_SERVER_ERROR,
|
||||||
|
'Internal server error'
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
exports.getUserExist = async (req, res) => {
|
exports.getUserExist = async (req, res) => {
|
||||||
try {
|
try {
|
||||||
const { account } = req.query
|
const { account } = req.query
|
||||||
|
|||||||
@ -13,4 +13,6 @@ router.get('/', function (req, res) {
|
|||||||
|
|
||||||
router.post('/login', userController.login)
|
router.post('/login', userController.login)
|
||||||
|
|
||||||
|
router.post('/logout', userController.logout)
|
||||||
|
|
||||||
module.exports = router
|
module.exports = router
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user