Skip to content
This repository has been archived by the owner on Aug 30, 2021. It is now read-only.

fix(users) Stops error on signin/signup #1495

Merged
merged 2 commits into from
Sep 11, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};
Expand All @@ -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)));
Expand All @@ -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);
};
Expand Down Expand Up @@ -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);
Expand All @@ -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);
}
}
});
Expand Down