From 3d6b04f75d350291f95fb9e4edc69a2fe367eb21 Mon Sep 17 00:00:00 2001 From: NGPixel Date: Sat, 23 Nov 2019 15:06:34 -0500 Subject: [PATCH] fix: handle email verification exceptions (#1227) --- server/controllers/auth.js | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/server/controllers/auth.js b/server/controllers/auth.js index 34753699..1b2ad03d 100644 --- a/server/controllers/auth.js +++ b/server/controllers/auth.js @@ -122,12 +122,16 @@ router.get('/register', async (req, res, next) => { * Verify */ router.get('/verify/:token', bruteforce.prevent, async (req, res, next) => { - const usr = await WIKI.models.userKeys.validateToken({ kind: 'verify', token: req.params.token }) - await WIKI.models.users.query().patch({ isVerified: true }).where('id', usr.id) - const result = await WIKI.models.users.refreshToken(usr) - req.brute.reset() - res.cookie('jwt', result.token, { expires: moment().add(1, 'years').toDate() }) - res.redirect('/') + try { + const usr = await WIKI.models.userKeys.validateToken({ kind: 'verify', token: req.params.token }) + await WIKI.models.users.query().patch({ isVerified: true }).where('id', usr.id) + const result = await WIKI.models.users.refreshToken(usr) + req.brute.reset() + res.cookie('jwt', result.token, { expires: moment().add(1, 'years').toDate() }) + res.redirect('/') + } catch (err) { + next(err) + } }) /**