我不明白为什么我有这个错误:
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('/')
}
***