cb=gapi.loaded_0?le=scs:230 未捕获的类型错误:无法解构"response.profileObj"的属性"name",因为它未定义



我一直得到这个错误,我不知道是什么原因。

const Login = () => {
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 });
});
};

如果我修改const { name, googleId, imageUrl } = response.profileObj ?? {};

然后我得到这个:Uncaught Error: createIfNotExists() requires that the document contains an ID ("_id" property)

你知道我错过了什么吗?

当我试图这样做时,我得到了同样的错误。在我的例子中,我发现googleId有时是空的,并导致这种类型的错误。我解决了这个问题,把一个IF语句之前声明在你的情况下doc const,只是检查如果googleId是空的。告诉我这对你是否合适,如果不行,我很乐意帮忙。

相关内容