Reactjs React Native-无法将displayName和photoURL保存到firebase

Reactjs React Native-无法将displayName和photoURL保存到firebase,reactjs,firebase,react-native,firebase-authentication,react-native-android,Reactjs,Firebase,React Native,Firebase Authentication,React Native Android,我发现在我的react原生项目中注册时,很难将用户的displayName和photoURL保存到firebase 我使用docs()作为指南 请参见下面我的代码: onRegister = () => { firebase.auth().createUserWithEmailAndPassword( this.state.typedEmail, this.state.typedPassword) .then((userCredentials) => { if(u

我发现在我的react原生项目中注册时,很难将用户的displayName和photoURL保存到firebase

我使用docs()作为指南

请参见下面我的代码:

  onRegister = () => {
  firebase.auth().createUserWithEmailAndPassword( this.state.typedEmail, this.state.typedPassword)
  .then((userCredentials) => {
    if(userCredentials.user) {
      console.warn(userCredentials.user)
      userCredentials.user.updateProfile({
        displayName: "Jane Q. User",
        photoURL: "https://example.com/jane-q-user/profile.jpg"
      })
      .then(() => {
        this.setState({ user: userCredentials.user })
        console.warn("yo:", this.state.user)
      })
    }
  }).catch((error) => {
      console.warn(`error:, ${error}`)
  })}
使用上述功能,我可以保存电子邮件和密码,但displayName和photoURL仍然返回null


请提供帮助。

您可以尝试重新加载,然后获取当前用户

async function updateProfile() {
  await firebase.auth().currentUser.updateProfile({
        displayName: "Jane Q. User",
        photoURL: "https://example.com/jane-q-user/profile.jpg"
      });
  await firebase.auth().currentUser.reload();
  console.log(firebase.auth().currentUser.displayName); <-- check if it is updated
}

谢谢@Tuan,请问我如何将其融入我的onRegister功能?我只是更新了我的答案。我改用了
async/await
onRegister = async () => {
  try {
    const userCredentials = await firebase
      .auth()
      .createUserWithEmailAndPassword(this.state.typedEmail, this.state.typedPassword);
    if (userCredentials.user) {
      console.warn(userCredentials.user);
      await userCredentials.user.updateProfile({
        displayName: 'Jane Q. User',
        photoURL: 'https://example.com/jane-q-user/profile.jpg',
      });
      await userCredentials.user.reload();
      this.setState({ user: firebase.auth().currentUser });
      console.warn('yo:', this.state.user);
    }
  } catch (error) {
    console.warn(`error:, ${error}`);
  }
};