From d22cff6532095bf8fa09d44a23801ea44035d2b5 Mon Sep 17 00:00:00 2001 From: alex-phillips Date: Wed, 19 Feb 2020 14:21:55 -0500 Subject: [PATCH] /ping is now 2 separate routes: /auth and /status to determine auth status and then application status --- routes/index.js | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/routes/index.js b/routes/index.js index bccc148..32ce529 100644 --- a/routes/index.js +++ b/routes/index.js @@ -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 }) })