【发布时间】:2022-11-06 10:33:51
【问题描述】:
我不断收到此错误,我不知道是什么原因造成的。
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)
知道我缺少什么吗?
【问题讨论】:
-
似乎您的
response.profileObj正在获取null或undefined。当您执行const {name} = {}时,您将得到undefined,因此您会收到该错误。尝试添加 if 条件并在profileObj有数据时执行这些语句 -
我试过但没有解决问题。我无法使用 google 登录并且不断收到 401 错误。
标签: reactjs react-google-login