Proč máte problém:
Nepoužíváte findOrCreate metoda dobře. findOrCreate může trvat až čtyři argumenty.findOrCreate(conditions, doc, options, callback) :
conditions:Používá se k určení filtru výběru k nalezení dokumentu.doc[nepovinné]:Pokud dokument odpovídá filtru výběru (conditions) nebyl nalezen, tentodocje sloučeno s tím, co máte vconditionsa poté vložen do DB.options[nepovinné]:Z kódové základny pluginů jsem usoudil, že můžete použítoptions.upsert(pokud je nastaveno natrue) pro aktualizaci dokumentu, pokud již existuje.callback:Funkce provedená po dokončení operace.
To, co děláte špatně, je passign { email: profile.emails[0].value } jako třetí argument kde options očekáváte, měli byste jej zahrnout do doc tedy druhý argument.
Oprava
Zkuste toto:
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);
}
);
}
)
);