是否可以在Firebase中向用户配置文件表添加自定义字段?
现在看来我只能将数据添加到:
- "uid">
- "displayName">
- "照片URL">
- "电子邮件">
- "emailVerified">
- "电话号码">
- "isAnonymous">
- "tenantId">
- "providerData":
- "apiKey">
- "appName">
- "authDomain">
- "stsTokenManager">
- "重定向事件ID">
- "lastLoginAt">
- "创建日期">
我希望能够将自定义对象添加到JSON字符串中,以包含所有用户数据。
https://firebase.google.com/docs/auth/web/manage-users
快速示例,在注册用户后,我将该用户添加到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!');
}
}