PassportJSで基本的なGoogle認証を取得しようとしています。ウェブ上の情報量はかなり限られているようで、私は問題を抱え続けているので、ここで試してみようと思いました。
https://github.com/mattgaidica/twitter-mongoのコードを使用していますが、Google OAuthで使用するためにいくつかの変更が加えられています(Twitterキーを使用せず、passport-googleを使用していますpassport.authenticate('google', ...)
)。
私はこのエラーで終わり続けます:'Error: failed to serialize user into session'
passport.serializeUser(function(user, done) {
console.log(user); //does not have the fields we created earlier, user.uid does not exist.
done(null, user.uid);
});
私のパスポート戦略:
passport.use(new GoogleStrategy({
returnURL: "http://localhost:3000/auth/google/callback"
},
function(identifier, profile, done) {
User.findOne({uid: profile.id}, function(err, user) {
if(user) {
done(null, user);
} else {
var user = new User();
user.provider = "google";
user.uid = identifier;
user.name = profile.displayName;
user.save(function(err) {
if(err) { throw err; }
done(null, user);
});
}
})
}
));
この他のユーザーのフィールドは最初に作成されたものと同じではありませんが、他のユーザーはどうなりましたか?
私はここで何が起こっているのか少し迷っています。誰かが私が間違っていることを教えてくれたら、私はとても感謝しています。