Hitman666/MEAN_MVC_3rdTutorial

res.redirect is undefined in saveOAuthUserProfile

Opened this issue · 3 comments

I face this problem and not yet solved. I think something is left from this code. anybody experienced the same problem ?

exports.saveOAuthUserProfile = function(req, profile, done){
    User.findOne({
        provider: profile.provider,
        providerId: profile.providerId,
    },
    function(err, user) {
        if (err) {
            return done(err);
        }
        else
        {
            if (!user) {
                // console.log(profile.email.value);
                var possibleUsername = profile.username || ((profile.email) ? profile.email.value.split('@')[0] : '');
                User.findUniqueUsername(possibleUsername, null, function(availableUsername){
                    profile.username = availableUsername;
                    user = new User(profile);

                    user.save(function(err){
                        if (err) {
                            var message = getErrorMessage(err);
                            // var message = _this.getErrorMessage(err);
                            req.flash('error', message);
                            return res.redirect('/register');
                        }

                        return done(err, user);
                    });
                });
            }
            else
            {
                return done(err, user);
            }
        }
    });
};

Actually, this is the exact code and nothing is missing. Can you please explain in more detail in which case you get this error?

i experience the same problem , the res object is not passed to the callback so you get and error in that line, but unfortunaly i dont khow yet how to fix this errors.

Hey, would you mind putting your example to Github so that I can clone it and try on your example?