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
public
async
validate(accessToken: string, refreshToken:string, profile: any, done: VerifyCallback): Promise<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;
return
newUser.save();
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.