/ping is now 2 separate routes: /auth and /status to determine auth status and then application status

This commit is contained in:
alex-phillips 2020-02-19 14:21:55 -05:00
parent e29e5f1fec
commit d22cff6532

View File

@ -77,7 +77,21 @@ router.post('/login', async (req, res, next) => {
})
})
router.get('/ping', async (req, res, next) => {
router.get('/auth', async (req, res, next) => {
if (!req.user) {
return res.status(401).json({
status: 'unauthorized',
result: null
})
}
return res.json({
status: 'ok',
result: req.user.toJSON()
})
})
router.get('/status', async (req, res, next) => {
if (!req.user) {
// If unauthenticated, check to make sure we have a user at all
const userCount = await User.count({
@ -90,16 +104,11 @@ router.get('/ping', async (req, res, next) => {
result: null
})
}
return res.json({
status: 'unauthorized',
result: 'not_logged_in'
})
}
return res.json({
status: 'ok',
result: req.user.toJSON()
result: null
})
})