javascript - Firebase 用户配置文件添加自定义字段
问题描述
是否可以将自定义字段添加到 Firebase 中的用户配置文件表?
现在看起来我只能将数据添加到:
- “uid”
- “显示名称”
- “照片网址”
- “电子邮件”
- “电子邮件已验证”
- “电话号码”
- “是匿名的”
- “租户 ID”
- “提供者数据”:
- “apiKey”
- “应用名称”
- “授权域”
- “stsTokenManager”
- “重定向事件 ID”
- “上次登录时间”
- “创建于”
我希望能够将自定义对象添加到 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...',
....
})
}
}
}
希望这可以帮助。
推荐阅读
- r - Using fileInput in shiny
- kubernetes - How to configure IP/listeners in Apache Kafka so that external clients can connect to it
- c# - Deserialize JSON to List in C# in a console application
- python - Python - 如何使用 Viber 机器人发送消息?
- android - 在 Dagger 1 项目中支持 Dagger 2 依赖项
- swift - 如何为表格视图中的不同部分使用不同的数组?
- javascript - 有没有办法检查何时添加了某人的角色?[不和谐.js]
- java - CrudRepository 按一对多关系过滤
- php - 如何制作多条路线::放入一个控制器(Laravel 6)
- faust - 如何将浮士德中的消费者设置为特定的偏移量