【发布时间】:2021-02-12 13:37:23
【问题描述】:
未捕获(承诺中)错误:请求失败,状态码为 400
我需要向数据库发出页面请求以登录系统,但我已经太困惑了,不知道如何消除此错误。 在此之前有错误“操作必须是普通对象。使用自定义中间件进行异步操作。” 之后我连接了 Redux-Thunk 并出现了当前的错误。
动作
export const auth = (email, password, isLogin) => {
return async(dispatch) => {
dispatch(authData())
let url = 'https://identitytoolkit.googleapis.com/v1/accounts:signUp?key=AIzaSyAU8gNE0fGG8z9zqUyh68Inw9_RzljhCCs'
if (isLogin) {
url = 'https://identitytoolkit.googleapis.com/v1/accounts:signInWithPassword?key=AIzaSyAU8gNE0fGG8z9zqUyh68Inw9_RzljhCCs'
}
const response = await axios.post(url, authData)
console.log(response.data)
}
}
const authData = (email, password, returnSecureToken = true) => ({
type: 'LOGIN',
email,
password,
returnSecureToken
})
组件
loginHandler = () => {
this.props.auth(
this.props.AuthMail,
this.props.AuthPass,
true
)
}
registerHandler = () => {
this.props.auth(
this.props.AuthRegMail,
this.props.AuthRegPass,
false
)
}
const mapDispatchToProps = dispatch => {
return {
auth: (email, password, isLogin) => dispatch(auth(email, password, isLogin))
}
}
【问题讨论】:
标签: javascript reactjs redux-thunk