aboutsummaryrefslogtreecommitdiff
path: root/src/auth.ts
diff options
context:
space:
mode:
authorHafeez2018-02-07 00:10:05 +0000
committerHafeez2018-02-07 00:10:05 +0000
commitc86122ea21e69d63a67a45b8eb91450df3d0ccf2 (patch)
treebdbb4b47fc608c809331b2c6964c140afadf9a26 /src/auth.ts
parentstarted creating authentication middleware (diff)
downloadmedicine-c86122ea21e69d63a67a45b8eb91450df3d0ccf2.tar.gz
medicine-c86122ea21e69d63a67a45b8eb91450df3d0ccf2.zip

added ensureAuth method

Diffstat (limited to 'src/auth.ts')
-rw-r--r--src/auth.ts9
1 files changed, 8 insertions, 1 deletions
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