【发布时间】:2021-03-30 12:26:21
【问题描述】:
在使用 firebase 登录后,我必须获取特定用户的用户个人资料详细信息。现在,它正在返回我的 firestore 中所有用户的详细信息。
在个人资料页面中获取详细信息的代码:
import React from 'react';
import firebase from 'firebase';
const firestore = firebase.firestore();
class ProfilePage extends React.Component {
state = {
profiledata : null
}
componentDidMount(){
firestore.collection('profiledata')
// .doc("JgT2LyOB4jqhMv9YMgrh")
.get()
.then((snapshot) => {
const profiledata = []
snapshot.forEach(function(doc){
const data = doc.data();
profiledata.push(data);
}
)
this.setState({profiledata : profiledata})
})
}
render(){
return(
<div className='profile'>
<h1>User</h1>
{
this.state.profiledata &&
this.state.profiledata.map( profiledata => {
return(
<div>
<p>
First Name : {String(profiledata.firstname)}
Last Name : {String(profiledata.lastname)}
Company Name : {String(profiledata.companyname)}
</p>
</div>
)
})
}
</div>
)
}export default ProfilePage;
这是我的输出:
first name : john lsatname: doe company: johndoe co
first name : Lisa lsatname: doe company: lisadoe co
first name : Roger lsatname: doe company: rogerdoe co
我的firestore集合中有三个用户,它在profilepage中给了我,现在的问题是如何根据谁登录/注册来获取特定的用户详细信息??
有什么建议吗??我该怎么做?
【问题讨论】:
标签: reactjs firebase google-cloud-firestore