【发布时间】:2022-06-20 05:37:33
【问题描述】:
const navigate = useNavigate();
const responseGoogle = (response) => {
localStorage.setItem('user', JSON.stringify(response.profileObj));
const { name, googleId, imageUrl } = response.profileObj;
const doc = {
_id: googleId,
_type: 'user',
userName: name,
image: imageUrl,
};
client.createIfNotExists(doc).then(() => {
navigate('/', { replace: true });
});
};
我收到“名称未定义”的错误 - 但如何? imageUrl 和 googleId 工作正常,那么 name 有什么问题?
【问题讨论】:
-
你能分享你的回应吗?对象会有所帮助
-
我如何分享@FaisalAhmed
-
我怀疑
googleId、imageUrl是否“工作正常”。您只是收到 name 的错误,因为它是它尝试解构的第一个属性并且它已经在那里失败了。此错误消息告诉您response.profileObj是undefined因此无法解构...
标签: reactjs google-api google-authentication