[英]Firebase User Profile Add Custom Fields
是否可以在 Firebase 中的用戶配置文件表中添加自定義字段?
現在看起來我只能將數據添加到:
我希望能夠將自定義對象添加到 JSON 字符串以包含所有用戶數據。
快速示例,在我注冊用戶后,我將該用戶添加到 usersCollection 並根據需要提供其他字段信息。
在我的 firebase 驅動的應用程序中,我所做的如下:
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...',
....
})
}
}
}
希望這可以幫助。
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!');
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.