Creating a signup component in my app using Firebase as the authentication method and database. After registering a new user, a key is generated and all user information, including the UID from authentication, is saved in the database. I want to use the UID from authentication as the primary key instead of the Firebase-generated key.
Here's the code snippet:
Component TypeScript file:
signupUser(user: User) {
this.firebaseAuth.auth
.createUserWithEmailAndPassword(user.email, user.password)
.then(value => {
console.log('Success!', value);
this.afdb.list('users').push({
firstname: user.firstname,
lastname: user.lastname,
email: user.email,
uid: value.uid
});
})
.catch(err => {
console.log('Something went wrong:',err.message);
});
}
JSON structure in Firebase:
users {
-KpgNYJ0adjVyOGJiyBF {
email: <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="3d49584e497d58ca45c584bc8f84868">[email protected]</a>
firstname: dasdsa
lastname: dsadsads
uid: 021oxk8X6rQL6gAfC0UhZpB4vZx2
}
}
Desired JSON structure:
users {
021oxk8X6rQL6gAfC0UhZpB4vZx2 {
email: <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="3440475146324047514632054844484a">[email protected]</a>
firstname: dasdsa
lastname: dsadsads
}
}
Your assistance is greatly appreciated. Thank you.
EDIT: Forgot to mention that I'm using AngularFire2.