mirror of
https://github.com/taobataoma/meanTorrent.git
synced 2026-05-06 13:46:18 +02:00
fix(authentication) Stops error on signin/signup (#1495)
Uses the passport info object to simplify login and remove the need to temporarily cache the redirect within the session.
This commit is contained in:
committed by
Michael Leanos
parent
b2a5cb5b6f
commit
67d1a5a1f6
@@ -85,11 +85,6 @@ exports.signout = function (req, res) {
|
||||
*/
|
||||
exports.oauthCall = function (strategy, scope) {
|
||||
return function (req, res, next) {
|
||||
// Set redirection path on session.
|
||||
// Do not redirect to a signin or signup page
|
||||
if (noReturnUrls.indexOf(req.query.redirect_to) === -1) {
|
||||
req.session.redirect_to = req.query.redirect_to;
|
||||
}
|
||||
// Authenticate
|
||||
passport.authenticate(strategy, scope)(req, res, next);
|
||||
};
|
||||
@@ -100,10 +95,8 @@ exports.oauthCall = function (strategy, scope) {
|
||||
*/
|
||||
exports.oauthCallback = function (strategy) {
|
||||
return function (req, res, next) {
|
||||
// Pop redirect URL from session
|
||||
var sessionRedirectURL = req.session.redirect_to;
|
||||
delete req.session.redirect_to;
|
||||
|
||||
// info.redirect_to contains inteded redirect path
|
||||
passport.authenticate(strategy, function (err, user, info) {
|
||||
if (err) {
|
||||
return res.redirect('/authentication/signin?err=' + encodeURIComponent(errorHandler.getErrorMessage(err)));
|
||||
@@ -116,7 +109,7 @@ exports.oauthCallback = function (strategy) {
|
||||
return res.redirect('/authentication/signin');
|
||||
}
|
||||
|
||||
return res.redirect(info || sessionRedirectURL || '/');
|
||||
return res.redirect(info.redirect_to || '/');
|
||||
});
|
||||
})(req, res, next);
|
||||
};
|
||||
@@ -145,6 +138,15 @@ exports.saveOAuthUserProfile = function (req, providerUserProfile, done) {
|
||||
$or: [mainProviderSearchQuery, additionalProviderSearchQuery]
|
||||
};
|
||||
|
||||
// Setup info object
|
||||
var info = {};
|
||||
|
||||
// Set redirection path on session.
|
||||
// Do not redirect to a signin or signup page
|
||||
if (noReturnUrls.indexOf(req.query.redirect_to) === -1) {
|
||||
info.redirect_to = req.query.redirect_to;
|
||||
}
|
||||
|
||||
User.findOne(searchQuery, function (err, user) {
|
||||
if (err) {
|
||||
return done(err);
|
||||
@@ -166,11 +168,11 @@ exports.saveOAuthUserProfile = function (req, providerUserProfile, done) {
|
||||
|
||||
// And save the user
|
||||
user.save(function (err) {
|
||||
return done(err, user);
|
||||
return done(err, user, info);
|
||||
});
|
||||
});
|
||||
} else {
|
||||
return done(err, user);
|
||||
return done(err, user, info);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user