【发布时间】:2021-07-02 13:43:24
【问题描述】:
我无法传递从 firebase 云函数创建的新创建用户的 uid。用户已成功创建,但 firestore 集合中的文档未成功创建。当我像这样从.doc() 中删除参数时,用户被创建但随机生成的uid 不是从创建用户ofc 创建的。我想要的是从创建的用户传递 uid 作为文档名称。 uid 可从createUsr 函数的响应中获得。
我认为我在使用异步函数的方式上做得不对。
const handleSubmit = async (values) => {
const createUsr = functions.httpsCallable('createUsr')
try {
await createUsr({ email: values.email }).then((data) => {
const id = data.uid
const newDocRef = db.collection('students').doc(id)
newDocRef.set({
userID: id,
firstName: values.firstName,
lastName: values.lastName,
access_type: "student"
})
})
success()
} catch {
error()
}
}
来自控制台的数据响应
Object
data:
disabled: false
displayName: null
email: "test@gmail.com"
emailVerified: false
metadata: {creationTime: "Tue, 06 Apr 2021 19:06:19 GMT", lastSignInTime: null, lastRefreshTime: null}
passwordHash: null
passwordSalt: null
phoneNumber: null
photoURL: null
providerData: []
tenantId: null
tokensValidAfterTime: "Tue, 06 Apr 2021 19:06:19 GMT"
uid: "GHpc2ykVj3RPnMqPDDiDiViVvmc2"
__proto__: Object
__proto__: Object
【问题讨论】:
-
尝试删除等待。
-
@KToxcon 它现在可以工作,但它会从随机生成的 uid 中创建用户,例如
data.uid从未通过 -
能否在控制台中记录数据并分享给我
-
@KToxcon 问题已更新为来自 concole 的回复
标签: reactjs firebase google-cloud-firestore firebase-authentication