简体   繁体   English

Firebase 用户配置文件添加自定义字段

[英]Firebase User Profile Add Custom Fields

Is it possible to add custom fields to the user profile table in Firebase?是否可以在 Firebase 中的用户配置文件表中添加自定义字段?

Right now it looks like I can only add data to:现在看起来我只能将数据添加到:

  • "uid" “uid”
  • "displayName" “显示名称”
  • "photoURL" “照片网址”
  • "email" “电子邮件”
  • "emailVerified" “电子邮件已验证”
  • "phoneNumber" “电话号码”
  • "isAnonymous" “是匿名的”
  • "tenantId" “租户 ID”
  • "providerData": “提供者数据”:
  • "apiKey" “apiKey”
  • "appName" “应用名称”
  • "authDomain" “授权域”
  • "stsTokenManager" “stsTokenManager”
  • "redirectEventId" “重定向事件 ID”
  • "lastLoginAt" “上次登录时间”
  • "createdAt" “创建于”

I would like to have the ability to add custom objects to the JSON string to contain all of the user data.我希望能够将自定义对象添加到 JSON 字符串以包含所有用户数据。

https://firebase.google.com/docs/auth/web/manage-users https://firebase.google.com/docs/auth/web/manage-users

Quick example, where after I have registered a user, I add that user to a usersCollection and supply other field information as necessary.快速示例,在我注册用户后,我将该用户添加到 usersCollection 并根据需要提供其他字段信息。

In my firebase powered app, what I do is the following:在我的 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...',
        ....
      })
    }
  }
}

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!');
    }

}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM