找不到使用Google身份验证的用户

时间:2018-07-12 03:09:23

标签: node.js mongodb express google-authentication

这是我的第一篇文章。目前,我正在使用node.js和express。 我正在追踪this tutorial,以使用node.js实现Google身份验证

我能够成功到达用户选择其帐户的身份验证部分,但是随后我发现抛出了错误。

这是错误来源:

// GOOGLE
passport.use(new GoogleStrategy({

    clientID        : configAuth.googleAuth.clientID,
    clientSecret    : configAuth.googleAuth.clientSecret,
    callbackURL     : configAuth.googleAuth.callbackURL,

},
function(token, refreshToken, profile, done) {

    // make the code asynchronous
    // User.findOne won't fire until we have all our data back from Google
    process.nextTick(function() {

        // try to find the user based on their google id
        User.findOne({ 'google.id' : profile.id }, function(err, user) {
            if (err)
                return done(err);
                console.log("user not found");

            if (user) {

                // if a user is found, log them in
                return done(null, user);

            } else {
                // if the user isnt in our database, create a new user
                var newUser          = new User();

                // set all of the relevant information
                newUser.google.id    = profile.id;
                newUser.google.token = token;
                newUser.google.name  = profile.displayName;
                newUser.google.email = profile.emails[0].value; // pull the first email

                // save the user
                newUser.save(function(err) {
                    if (err)

                        throw err;
                    return done(null, newUser);
                });
            }
        });
    });

}));

另外,我找不到包含console.log(err)用户的堆栈跟踪信息:

  

找不到用户   events.js:160         投掷者//未处理的“错误”事件         ^

TypeError:无法设置未定义的属性“ id”     在/home/ubuntu/workspace/education/facebook/app.js:184:42     在查询。 (/home/ubuntu/workspace/education/node_modules/mongoose/lib/model.js:3407:16)     在/home/ubuntu/workspace/education/node_modules/mongoose/node_modules/kareem/index.js:259:21     在/home/ubuntu/workspace/education/node_modules/mongoose/node_modules/kareem/index.js:127:16     在_combinedTickCallback(内部/进程/next_tick.js:73:7)     在process._tickCallback(internal / process / next_tick.js:104:9)

我怀疑问题出在Google无法找到用户。我应该采取什么方向解决这个问题?谢谢!感谢您的帮助

0 个答案:

没有答案