使用 firebase 的经过身份验证的用户的信息没有出现在 React Native 中
Information of authenticated user using firebase didn't appear in React Native
我使用 firebase 登录到我的应用程序,然后我尝试使用下图中的以下代码显示用户信息,但输出仅显示用户的电子邮件。有谁知道我怎样才能显示所有信息?
代码:
import React, { Component } from 'react';
import { StyleSheet, Text, Image, View } from 'react-native';
import firebase from "firebase/compat/app"
import "firebase/compat/auth"
import "firebase/compat/firestore"
export default class Profile extends Component {
state = { user: {} };
componentDidMount() {
firebase.auth().onAuthStateChanged((user) => {
if (user != null) {
this.setState({ user: user });
}
})
}
render = () => {
return (
<View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
<Text>Profile Screen</Text>
<Image style={{ width: 100, height: 100, borderRadius: 50 }} source={{ uri: this.state.user.photoUrl }} />
<Text>{this.state.user.givenName}</Text>
<Text>{this.state.user.familyName}</Text>
<Text>{this.state.user.photoUrl}</Text>
<Text>{this.state.user.email}</Text>
</View>
);
}
}
输出:
我认为您应该在登录时更新配置文件并在其中添加所有数据。像这样
import { getAuth, updateProfile } from "firebase/auth";
const auth = getAuth();
updateProfile(auth.currentUser, {
displayName: "Jane Q. User", photoURL: "https://example.com/jane-q-
user/profile.jpg"
}).then(() => {
// Profile updated!
// ...
}).catch((error) => {
// An error occurred
// ...
});
我使用 firebase 登录到我的应用程序,然后我尝试使用下图中的以下代码显示用户信息,但输出仅显示用户的电子邮件。有谁知道我怎样才能显示所有信息?
代码:
import React, { Component } from 'react';
import { StyleSheet, Text, Image, View } from 'react-native';
import firebase from "firebase/compat/app"
import "firebase/compat/auth"
import "firebase/compat/firestore"
export default class Profile extends Component {
state = { user: {} };
componentDidMount() {
firebase.auth().onAuthStateChanged((user) => {
if (user != null) {
this.setState({ user: user });
}
})
}
render = () => {
return (
<View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
<Text>Profile Screen</Text>
<Image style={{ width: 100, height: 100, borderRadius: 50 }} source={{ uri: this.state.user.photoUrl }} />
<Text>{this.state.user.givenName}</Text>
<Text>{this.state.user.familyName}</Text>
<Text>{this.state.user.photoUrl}</Text>
<Text>{this.state.user.email}</Text>
</View>
);
}
}
输出:
我认为您应该在登录时更新配置文件并在其中添加所有数据。像这样
import { getAuth, updateProfile } from "firebase/auth";
const auth = getAuth();
updateProfile(auth.currentUser, {
displayName: "Jane Q. User", photoURL: "https://example.com/jane-q-
user/profile.jpg"
}).then(() => {
// Profile updated!
// ...
}).catch((error) => {
// An error occurred
// ...
});