From 619292b853bb23515b4ed760ce6e57d07ef2335c Mon Sep 17 00:00:00 2001 From: cha0s Date: Sat, 18 Jul 2020 16:59:00 -0500 Subject: [PATCH] refactor: redirect logged-in to chat & clear state --- src/server/routes/user.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/server/routes/user.js b/src/server/routes/user.js index 66cfdcb..9e08db6 100644 --- a/src/server/routes/user.js +++ b/src/server/routes/user.js @@ -11,9 +11,16 @@ export default function userRoutes(app) { app.get('/auth/reddit/callback', (req, res, next) => { if (req.query.state === req.session.state) { passport.authenticate('reddit', { - successRedirect: '/', + successRedirect: '/chat', failureRedirect: '/login', - })(req, res, next); + })(req, res, (error) => { + if (error) { + next(error); + return; + } + delete req.session.state; + req.session.save(next); + }); } else { res.status(403).end('Forbidden: state mismatch');