我有这个React Redux Firebase应用程序 .
在商店中,我们有一个userReducer只有一个名为authed的状态属性,如果用户是否被记录则是一个布尔值 .
我有这个 config.js
文件,用于配置firebase功能和东西 .
export const ref = firebase.database().ref();
export const firebaseAuth = firebase.auth;
export function login (email, pw) {
return firebaseAuth().signInWithEmailAndPassword(email, pw)
}
逻辑如下>在开始时authed值为false,然后我们使用创建帐户
export function auth(email, pw) {
return firebaseAuth().createUserWithEmailAndPassword(email, pw)
.then(saveUser);
}
然后在 App.js
我们有
componentDidMount() {
this.removeListener = firebaseAuth().onAuthStateChanged((user) => {
if (user) this.props.authed_true();
else this.props.authed_false();
})
}
componentWillUnmount () {
this.removeListener()
}
来自redux的 this.props.authed_true/false
函数只需更改状态的authed prop,具体取决于是否有用户 .
如果authed为true,意味着我们有一个用户有一个重定向到某个路由 .
现在让我们明白这一点 .
注册用户是完美的,但是当我尝试使用Login时
export function login (email, pw) {
return firebaseAuth().signInWithEmailAndPassword(email, pw)
}
我得到了
错误:发生网络错误(例如超时,中断连接或无法访问的主机) .
我的网址栏变成了
从
至
http://localhost:3000/login?email=anorak%40abv.bg&password=anorak97
那么为什么login()不起作用?有任何想法吗?
2 回答
操作应该是对象,但是
login
动作创建器函数正在返回异步处理的promise . 这是redux-thunk的一个很好的用例 . 使用该库,您可以将其更改为:你的代码不好,你应该考虑推杆
在中间件中,因为它是登录后的副作用,你可以试试这样的东西
But 这不是您的问题,很可能您的标记中只有一个元素,并且在 Submit 后更改了URL,因此您应该尝试删除第一个