Waarom je het probleem hebt:
U gebruikt de findOrCreate . niet methode goed. findOrCreate kan maximaal vier argumenten bevatten.findOrCreate(conditions, doc, options, callback) :
conditions:Dit wordt gebruikt om het selectiefilter te specificeren om het document te vinden.doc[optioneel]:Als een document overeenkomt met het selectiefilter (conditions) niet gevonden, dezedocis samengevoegd met wat je hebt inconditionsen vervolgens in de DB ingevoegd.options[optioneel]:uit de codebase van de plug-in, dacht ik dat jeoptions.upsert. kunt gebruiken (indien ingesteld optrue) om het document bij te werken als het al bestaat.callback:De functie die wordt uitgevoerd nadat de bewerking is uitgevoerd.
Wat je verkeerd doet, is wachtwoord { email: profile.emails[0].value } als het derde argument waarbij options wordt verwacht, moet u dit opnemen in het doc d.w.z. het tweede argument.
De oplossing
Probeer dit:
passport.use(
new GoogleStrategy(
{
clientID: process.env.CLIENT_ID,
clientSecret: process.env.CLIENT_SECRET,
callbackURL: "https://localhost:3000/auth/google/dashboard",
profileFields: ["id", "displayName", "photos", "email"]
},
function(accessToken, refreshToken, profile, cb) {
console.log(profile);
console.log(profile.photos[0].value);
User.findOrCreate(
{ googleId: profile.id },
// Notice that this function parameter below
// includes both the profilePic and email
{ profilePic: profile.photos[0].value, email: profile.emails[0].value },
function(err, user) {
return cb(err, user);
}
);
}
)
);