I do have a react with firebase project. So I successfully able to login the user via firebase authentication. What I want to do is to set the user details in all pages. I thought, I can able to access the user variables in react everywhere like laravel's Auth::user() . But I tried in so many ways to achieve that. But I couldn't able to get the user details in another page. Is there any way to get the user details in another page ?
My signin.js page .
handleSubmit = (e) => {
e.preventDefault()
firebase.auth().signInWithEmailAndPassword(this.state.email, this.state.password).then((user) => {
alert("login success")
console.log(user.user)
this.setState({uid:user.user.uid})
localStorage.setItem('uid',JSON.stringify(user.user))
window.location.assign('/')
}).catch(function(error) {
console.log(error.code)
alert(error.message)
})
}
My dashboard.js page where I want to access user variables .
componentDidMount() {
if(localStorage.getItem('uid')){
//alert("welcome"+localStorage.getItem('uid'));
this.setState({user : JSON.parse(localStorage.getItem('uid'))})
console.log("this : "+localStorage.getItem('uid'))
}
}