【发布时间】:2021-02-09 14:21:27
【问题描述】:
我正在做一个简单的用户创建,但是firestore中的id字段为null并且id不同。
为什么会这样?如何解决?
代码如下:
const auth = await authFB().createUserWithEmailAndPassword(data.email, data.password);
const db = firestore();
await db
.collection('Clients')
.doc(auth.user.uid)
.set({
id: auth.user.uid,
name: {
first: firstName,
last: lastName
}
});
文档图片如下:(看id:null):
【问题讨论】:
-
是用户在 Auth 数据库中创建的吗?也许 authFB().createUserWithEmailAndPassword 会抛出错误。试着抓住它并检查
-
@SergeiSevriugin 我是这样使用的:import authFB from '@react-native-firebase/auth';
-
@SergeiSevriugin 它没有返回错误只是正常注册用户
-
我不明白,在您的代码中,您为文档设置了 id 和 name 属性,文档等于 auth.user.uid?那么当你创建这个文档时,如果你刚刚从 createUserWithEmailAndPassword 得到这个 id 呢?如果您使用 auth.user.uid 正确设置了名称名称属性,那么未设置 id 吗?
-
@SergeiSevriugin 是的,这是我的问题,id 为空,如果我创建 console.log (user.uid),uid 与 firestore 中的文档 id 不同
标签: javascript firebase react-native google-cloud-firestore react-native-firebase