Is it possible to add custom fields to the user profile table in Firebase?
Right now it looks like I can only add data to:
I would like to have the ability to add custom objects to the JSON string to contain all of the user data.
Quick example, where after I have registered a user, I add that user to a usersCollection and supply other field information as necessary.
In my firebase powered app, what I do is the following:
import app from 'firebase/app'
import 'firebase/auth'
import 'firebase/database'
import 'firebase/firestore'
const config = {
apiKey: process.env.REACT_APP_API_KEY,
authDomain: process.env.REACT_APP_AUTH_DOMAIN,
databaseURL: process.env.REACT_APP_DATABASE_URL,
projectId: process.env.REACT_APP_PROJECT_ID,
storageBucket: process.env.REACT_APP_STORAGE_BUCKET,
messagingSenderId: process.env.REACT_APP_MESSAGING_SENDER_ID
}
class Firebase {
constructor (props) {
app.initializeApp(config)
this.auth = app.auth()
this.db = app.database()
this.firestore = app.firestore()
}
signUpWithEmailAndPassword = (email, pw) => {
this.auth.createUserWithEmailAndPassword(email, password)
.then(registeredUser => {
this.firestore.collection("usersCollection")
.add({
uid: registeredUser.user.uid,
field: 'Info you want to get here',
anotherField: 'Another Info...',
....
})
}
}
}
Hope this helps.
auth()
.createUserWithEmailAndPassword(email, password)
.then((res) => {
console.log('User account created & signed in!', res);
res.user.updateProfile({
displayName: "Hanzala",
photoURL:"https://placeimg.com/140/140/any",
})
})
.catch(error => {
if (error.code === 'auth/email-already-in-use') {
console.log('That email address is already in use!');
}
}
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.