Redirect back to original destination after a successful sign-in via OAuth
This commit is contained in:
29
app.js
29
app.js
@ -85,8 +85,15 @@ app.use(function(req, res, next) {
|
||||
next();
|
||||
});
|
||||
app.use(flash());
|
||||
app.use(app.router);
|
||||
app.use(express.static(path.join(__dirname, 'public'), { maxAge: week }));
|
||||
app.use(function(req, res, next) {
|
||||
if (req.method !== 'GET') return next();
|
||||
var path = req.path.split('/')[1];
|
||||
if (/(auth|login|logout|signup)$/.test(path)) return next();
|
||||
req.session.returnTo = req.path;
|
||||
next();
|
||||
});
|
||||
app.use(app.router);
|
||||
app.use(function(req, res) {
|
||||
res.status(404);
|
||||
res.render('404');
|
||||
@ -141,15 +148,25 @@ app.get('/api/linkedin', passportConf.isAuthenticated, passportConf.isAuthorized
|
||||
*/
|
||||
|
||||
app.get('/auth/facebook', passport.authenticate('facebook', { scope: ['email', 'user_location'] }));
|
||||
app.get('/auth/facebook/callback', passport.authenticate('facebook', { successRedirect: '/', failureRedirect: '/login' }));
|
||||
app.get('/auth/facebook/callback', passport.authenticate('facebook', { failureRedirect: '/login' }), function(req, res) {
|
||||
res.redirect(req.session.returnTo || '/');
|
||||
});
|
||||
app.get('/auth/github', passport.authenticate('github'));
|
||||
app.get('/auth/github/callback', passport.authenticate('github', { successRedirect: '/', failureRedirect: '/login' }));
|
||||
app.get('/auth/github/callback', passport.authenticate('github', { failureRedirect: '/login' }), function(req, res) {
|
||||
res.redirect(req.session.returnTo || '/');
|
||||
});
|
||||
app.get('/auth/google', passport.authenticate('google', { scope: 'profile email' }));
|
||||
app.get('/auth/google/callback', passport.authenticate('google', { successRedirect: '/', failureRedirect: '/login' }));
|
||||
app.get('/auth/google/callback', passport.authenticate('google', { failureRedirect: '/login' }), function(req, res) {
|
||||
res.redirect(req.session.returnTo || '/');
|
||||
});
|
||||
app.get('/auth/twitter', passport.authenticate('twitter'));
|
||||
app.get('/auth/twitter/callback', passport.authenticate('twitter', { successRedirect: '/', failureRedirect: '/login' }));
|
||||
app.get('/auth/twitter/callback', passport.authenticate('twitter', { failureRedirect: '/login' }), function(req, res) {
|
||||
res.redirect(req.session.returnTo || '/');
|
||||
});
|
||||
app.get('/auth/linkedin', passport.authenticate('linkedin', { state: 'SOME STATE' }));
|
||||
app.get('/auth/linkedin/callback', passport.authenticate('linkedin', { successRedirect: '/', failureRedirect: '/login' }));
|
||||
app.get('/auth/linkedin/callback', passport.authenticate('linkedin', { failureRedirect: '/login' }), function(req, res) {
|
||||
res.redirect(req.session.returnTo || '/');
|
||||
});
|
||||
|
||||
/**
|
||||
* OAuth routes for API examples that require authorization.
|
||||
|
Reference in New Issue
Block a user