diff options
| author | Hafeez | 2018-02-07 00:10:05 +0000 |
|---|---|---|
| committer | Hafeez | 2018-02-07 00:10:05 +0000 |
| commit | c86122ea21e69d63a67a45b8eb91450df3d0ccf2 (patch) | |
| tree | bdbb4b47fc608c809331b2c6964c140afadf9a26 | |
| parent | started creating authentication middleware (diff) | |
| download | medicine-c86122ea21e69d63a67a45b8eb91450df3d0ccf2.tar.gz medicine-c86122ea21e69d63a67a45b8eb91450df3d0ccf2.zip | |
added ensureAuth method
| -rw-r--r-- | src/auth.ts | 9 |
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 |
