reactjs - 为什么会出现firebase授权错误?
问题描述
我不明白为什么我有这个错误:
auth.js:204 POST https://www.googleapis.com/identitytoolkit/v3/relyingparty/verifyPassword?key=AIzaSyApbrATkWmIfa0wkxIC9105e4K46ytzI4g 400
例如,当我在登录时输入了正确的电子邮件和错误的密码,或者当我使用已在使用的电子邮件注册新用户时,就会发生这种情况。
import firebase from 'firebase/app'
import { IUser } from '../models/user'
import { authTypes } from '../store/reducers/authReducer'
export function signIn(
credentials: IUser
): (dispatch: Function, getState: object) => void {
return (dispatch: Function, getState: object) => {
firebase
.auth()
.signInWithEmailAndPassword(credentials.email, credentials.password)
.then((res) => {
console.log(res)
dispatch({ type: authTypes.LOGIN })
})
.catch((err): any => {
dispatch({ type: authTypes.LOGIN_ERR, payload: err.message })
})
}
}
export function signUp(
newUser: IUser
): (
dispatch: Function,
getState: object,
{ getFirestore }: { getFirestore: any }
) => void {
return (
dispatch: Function,
getState: object,
{ getFirestore }: { getFirestore: any }
) => {
const firestore = getFirestore()
firebase
.auth()
.createUserWithEmailAndPassword(newUser.email, newUser.password)
.then(res => {
return firestore.collection('users').doc(res?.user?.uid).set({
firstName: newUser.firstName,
lastName: newUser.lastName,
})
}).catch((err): any => {
dispatch({ type: authTypes.SIN_UP_ERR, payload: err.message })
})
}
}
export function signOut(): (dispatch: Function, getState: object) => void {
return (dispatch: Function, getState: object) => {
firebase
.auth()
.signOut()
.then(() => {
console.log()
})
}
}
另外举个例子,我给出了 Login 组件的一部分:
const Login = () => {
const auth = useSelector((state: RootState) => state.firebase.auth)
const authP = useSelector((state: RootState) => state.auth.authErrorLogin)
const history = useHistory()
const dispatch = useDispatch()
const { handleSubmit, handleChange, state, errors } = useForm(
submit,
validateFormRegister2
)
function submit() {
dispatch(signIn(state as IUser))
history.push('/')
}
***
解决方案
推荐阅读
- java - Spring Boot 部署战争
- python - 当我在 wormy.py 中吃第二个苹果时添加分数
- oracle - 在异常中调用过程
- php - 问题:在 codeigniter 中找不到类“CI_Config”
- javascript - 甚至 json 是正确的 json 解析在 java 脚本中不起作用?
- php - 在 Web 和应用程序之间共享通用身份验证令牌
- transformation - 半正态分布下的面积太大
- python - 在 django 中配置 % static 的输出
- python - 如何从机器人框架中的列表中选择一个随机值?
- python - 删除以 NLTK 开头的句子的停用词