我使用路由配方,使用户能够查看/重定向之间的页面,这取决于用户是否登录(https://github.com/prescottprue/react-redux-firebase/blob/next/docs/recipes/routing.md-react-routerv4+redux-auth-wrapperv2)。
当我注销时,它确实会重定向到登录页面,但仍然是空白的,并且我收到了以下错误:
"Uncaught Error: Supplied prop/s "dispatch" are reserved for internal firebaseConnect() usage."我的Login.js组件使用的是firebaseConnect()。如果一个组件正在使用firebase,并且它也在使用firebase的另一个组件上使用,会出现问题吗?
在我遵循的教程中,firebase、react-redux-firebase的版本确实不同,但我确实根据文档设置了所有内容,并尝试使用最新的版本。我不知道这是否与问题有关。
来自App.js:
<Route
exact
path="/login"
component={UserIsNotAuthenticated(Login)}
/>来自Login.js:
onSubmit = e => {
e.preventDefault();
const { firebase } = this.props;
const { email, password } = this.state;
firebase
.login({
email,
password
})
.catch(err => alert('Invalid Login Credentials'));
};
export default firebaseConnect()(Login);package.json:
"dependencies": {
"classnames": "^2.2.6",
"firebase": "^6.0.2",
"history": "^4.9.0",
"react": "^16.8.6",
"react-dom": "^16.8.6",
"react-redux": "^7.0.3",
"react-redux-firebase": "^3.0.0-alpha.12",
"react-router-dom": "^5.0.0",
"react-scripts": "3.0.0",
"redux": "^4.0.1",
"redux-auth-wrapper": "^2.1.0",
"redux-firestore": "^0.7.4"
},发布于 2019-05-17 13:30:42
我设法解决了这个问题。在通过文档(http://docs.react-redux-firebase.com/history/v3.0.0/docs/recipes/routing.html)时,UserIsNotAuthenticated直接在组件中使用,而不是在路由级别,与withFirebase一起使用。
所以它看起来像这样: App.js -删除Login路由上的UserIsNotAuthenticated:
<Route exact path="/login" component={Login} />
Login.js:
import { compose } from 'redux';
import { withFirebase } from 'react-redux-firebase';
import { UserIsNotAuthenticated } from '../../helpers/auth';..。
export default compose(
UserIsNotAuthenticated,
withFirebase
)(Login);现在一切都正常了。一旦登录,您将从登录页面重定向到主页,当您注销时,您将重定向到登录页面。
https://stackoverflow.com/questions/56164386
复制相似问题