相关文章推荐
紧张的小熊猫  ·  Pattern matching ...·  2 年前    · 
心软的铁板烧  ·  react-native - react ...·  2 年前    · 
苦恼的打火机  ·  OSError: [WinError ...·  2 年前    · 
近视的手套  ·  1.4 ...·  2 年前    · 
Hello! I am currently working on a project where I would like users to be able to connect via google and save their data in my database (MongoDB). the redirection works perfectly but when I connect with my account I get an error like:
Cannot read property '0' of undefined.
What I have tried:
file: google.strategy.ts
TypeScript
public async validate(accessToken: string, refreshToken:string, profile: any, done: VerifyCallback): Promise<User> { // const { name, emails, photos } = profile // const user = { // email: emails[0].value, // firstName: name.givenName, // lastName: name.familyName, // picture: photos[0].value, // accessToken // done(null, user); const newUser = new this .UserModel(); newUser.userId = uuidv4(); newUser.accessToken = accessToken; newUser.name = profile.name.giveName + ' ' + profile.name.familyName; newUser.email = profile.emails[ 0 ].value; newUser.phone = profile.phone[ 0 ].value; newUser.picture = profile.photos[ 0 ].value; // done(null, newUser); return newUser.save();
TypeScript
public async validate(accessToken: string, refreshToken:string, profile: any, done: VerifyCallback): Promise<any> { const newUser = new this .UserModel(); newUser.userId = uuidv4(); newUser.accessToken = accessToken; newUser.name = profile.name.givenName + ' ' + profile.name.familyName; newUser.email = profile.emails[ 0 ].value; newUser.picture = profile.photos[ 0 ].value; return newUser.save( function (err) { if (err) throw err; return done( null , newUser);
  • Read the question carefully.
  • Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  • If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
  • Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question. Let's work to help developers, not make them feel stupid.
  •