I'm a beginner when it comes to using async
and await
, and I could really use some assistance.
In my code, there's a function called register
which registers a user and sends their data to the server to create a "user profile". However, I'm running into an issue with another async function called login
. This function redirects the user immediately after registration, so the "user profile" data is not being sent.
Take a look at my register
function below:
async register(user: User) {
try {
const result = await this.afAuth.auth.createUserWithEmailAndPassword(user.email, user.password);
await this.afAuth.auth.currentUser.updateProfile({
displayName: user.displayName,
photoURL: ""
}).then(() => {
let currentUser = result;
let date = new Date().getTime();
let userData = {
email: currentUser.email,
displayName: currentUser.displayName,
uid: currentUser.uid,
created: date,
}
this.database.list('users').set(userData.uid, userData).then(() => {
return;
}); //I want to continue after this line is called.
return;
}, function(error) {
console.log(error)
});
} catch(e) {
console.log(e);
}
}
It seems like my await
might be in the wrong place. I need the login
function to wait until the data is successfully .set
...
If you have any insights on what I might be doing incorrectly, I would greatly appreciate your help. Thank you!