首页 > 解决方案 > 为什么会出现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('/')
  }
***

请帮助... 捕获有关错误密码的错误,但也在控制台中输入了这篇文章中指定的错误。

标签: reactjsfirebasegoogle-cloud-firestorefirebase-authenticationredux-firestore

解决方案


推荐阅读