I cant pass the uid from the newly created user that is created from a firebase cloud function. The user is created successfully but the document in collection of the firestore is not. When i remove the argument from .doc() like this the user is created but with the random generated uid not the one created from the create user ofc. What i would like is to pass the uid from the created user to as the doc name. The uid is available from the response of the createUsr function.
I think i'm not doing something right with the way i'm using the async function.
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()
}
}
Data response from the console
Object
data:
disabled: false
displayName: null
email: "[email protected]"
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
data.uidwas never passed - Filip Simin