1
我正在寻找一种方式,当用户授权时,我存储user authorized status
所以我每次都可以检查用户是否是authorized
。然而,当我执行下面的代码未授权用户:(Master.jsx - >渲染())存储用户的反应授权
<Route exact path="/" render={() => {
console.log('this.props.authed: ', this.props.authed, "this.props: ", this.props)
return (
this.props.authed
? <Home />
: <Redirect from="/" to="/login"/>
)}
}/>
我通过firebase
在componentWillMount()
检查用户授权和存储它下面的代码:(Master.jsx - > componentWillMount())
componentWillMount =() => {
firebaseAuth().onAuthStateChanged((user) => {
if (user) {
this.props.login(user)
} else {
this.props.logout()
}
})
}
的问题是,将后<Route ..
所以用户将被routing
后授权componentWillMount
将被执行。我有什么办法解决它?
如果您看到我的问题,问题是我的存储处理器将在调用react-router后执行。因此,在我将用户数据存储在用户被授权'react-router'重定向到另一页的redux商店之前! –