0

我目前正在做一个项目,我希望用户能够通过谷歌连接并将他们的数据保存在我的数据库(MongoDB)中。重定向效果很好,但是当我连接到我的帐户时,我收到如下错误:

无法读取未定义的属性“0”

google.startegy.ts 文件:

 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();
    }
4

0 回答 0