I have this firebase method that creates a firebase user using a email and password
async register(name, email, password,type) {
let id;
const createUser = this.functions.httpsCallable('createUser');
return await this.auth.createUserWithEmailAndPassword({email,password })
.then((newUser)=>{
id = newUser.user.uid;
newUser.user.updateProfile({
displayName: name
})
})
.then(()=>{
createUser({
id:id,
name:name,
email:email,
type:type
})
})
}
It also adds the user to a firestore collection using a cloud function that takes the user details and user type.
I have 3 Promises (
createUserWithEmail...()
updateUserProfile()1
createUser()
) which Are dependent on each other.. How do I use them in one function?
NB : Couldn't use the functions.auth.user().onCreate()
method because of the user type field
How do I write this method without using the .then()
? Some users aren't appearing in the database
to remove .then
simply use await
"better"
async register(name, email, password,type) {
let id;
const createUser = this.functions.httpsCallable('createUser');
const newUser = await this.auth.createUserWithEmailAndPassword({email,password });
id = newUser.user.uid;
// assuming the next two functions are asynchrnous AND return a promise
// if not, just remove await
await newUser.user.updateProfile({displayName: name});
await createUser({
id:id,
name:name,
email:email,
type:type
});
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.