我是Nodejs和Express服务器的新手。我正在尝试创建一个webapp,用户可以用Gmail登录。我的前端使用Reactjs。然而,我一直收到这个错误TypeError:无法设置未定义的属性(设置“user”)
这是我的密码。我对一个没有Reactjs的简单登录/注销前端使用了一种非常类似的方法,它可以工作。然而,我不知道这个不断抛出错误的脚本发生了什么。任何见解都将不胜感激!
passport.serializeUser((user,cb)=>{process.next选择(()=>{return cb(null,{id:user?.id,email:用户?.email,googleId:用户?.googleId});});});passport.deserializeUser(async(user,cb)=>{process.nextTick(async()=>{尝试{const dbUser=等待getMemberById(用户?.id);if(dbUser){dbUser.email=用户?。电子邮件;dbUser.googleId=用户?。谷歌ID;}cb(空,dbUser);}捕获(错误){cb(误差);}});});passport.use(新谷歌战略({客户端ID:process.env。GOOGLE_CLIENT_ID,clientSecret:process.env。GOOGLE_CLIENT_SECRET公司,回调URL:'http://localhost:3002/auth/google/callback'},async(token,tokenSecret,profile,done)=>{尝试{console.log('Google profile:',profile);let user=等待getMemberByName(profile.id);if(!用户){console.log(“找不到用户,创建新用户”);user=等待createMember(profile.emails[0].value,profile.id);console.log(“新建用户:”,user);}user.email=档案.emails?。[0]?.值||null;//将电子邮件添加到用户对象(如果存在)user.googleId=配置文件id;//将googleId添加到用户对象console.log('序列化前的用户对象:',User);返回完成(null,user);}捕获(错误){console.log(“身份验证过程中出错:”,错误);return done(error,null);}}));
我尝试了对多个来源进行研究,但对将passportjs贬低到以前的版本毫无帮助。