From c86122ea21e69d63a67a45b8eb91450df3d0ccf2 Mon Sep 17 00:00:00 2001 From: Hafeez Date: Wed, 7 Feb 2018 00:10:05 +0000 Subject: added ensureAuth method --- src/auth.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'src/auth.ts') diff --git a/src/auth.ts b/src/auth.ts index c587fcf..fb37787 100644 --- a/src/auth.ts +++ b/src/auth.ts @@ -52,6 +52,11 @@ function checkErr(req, res, next) { next(); } +//Checks if user is still authenticated otherwise redirects +function ensureAuthenticated(req, res, next) { + if (req.isAuthenticated()) { return next(); } + res.redirect('/login'); +} //Configure local strategy to use with passport-js. @@ -89,4 +94,6 @@ app.post('/login', checkErr, passport.authenticate('local', function(err, user) } }), genToken); -app.get('/logout', ) \ No newline at end of file +app.get('/logout', function(req, res) { + req.logout(); +}); \ No newline at end of file -- cgit v1.2.1