From 5917e75dda17cf447020b59cf3cb0b67fe68950b Mon Sep 17 00:00:00 2001 From: Jack Date: Sat, 21 Oct 2017 15:10:55 -0400 Subject: [PATCH] Small auth fixes --- app/routes/auth.js | 2 ++ app/routes/routes.js | 6 +++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/app/routes/auth.js b/app/routes/auth.js index 33ef6bc..99b46b1 100644 --- a/app/routes/auth.js +++ b/app/routes/auth.js @@ -38,6 +38,7 @@ router.post('/register', function (req, res, next) { req.session.save(function(err) { if (err) return next(err); useInvite(req.body.invite, req.body.username); + req.session.username = req.body.username; res.status(200).json({'message': 'Registered.'}); }); }); @@ -55,6 +56,7 @@ router.post('/login', function (req, res, next) { if (!user) return res.status(401).json({'message': info}); req.logIn(user, function(err) { if (err) return next(err); + req.session.username = user; res.status(200).json({'message': 'Logged in.'}); }); })(req, res, next); diff --git a/app/routes/routes.js b/app/routes/routes.js index 1e0a6ed..5ff6175 100644 --- a/app/routes/routes.js +++ b/app/routes/routes.js @@ -12,10 +12,10 @@ var fs = require('fs'); var path = require('path'); var requireLogin = function(req, res, next) { - if (!req.session.passport.user) - res.redirect('/login'); + if (!req.session || !req.session.passport) + return res.redirect('/login'); else - next(); + return next(); }; module.exports = function(app) {