使用 redux-thunk 使用 firebase 进行注册身份验证

时间:2021-04-05 04:43:39

标签: firebase react-native firebase-authentication redux-thunk

我正在尝试使用 redux-thunk 在 firebase 中注册/添加用户。我正在尝试添加用户的电子邮件 ID 和密码。在提交时,我正在触发我的提交处理程序,在其中我正在调度一个动作“auth”,我的动作代码是:-

`export const SIGNUP ='SIGNUP';

  export const signup = (email, password ) =>{
   return async dispatch =>{
   let response;
   try{
    response = await fetch('https://identitytoolkit.googleapis.com/v1/accounts:signUp?key=[My-API- 
    Key]',
        {
          method: 'POST',
          headers: {
            'Content-Type': 'application/json'
          },
          body: JSON.stringify({
            email: email,
            password: password,
            returnSecureToken: true
          })
        });
      console.log(response)
      } catch(e){
       console.log(e);
     }
    // if(!response.ok){
    //     throw new Error('Something went wrong!');
    // }
      const resData = await response.json();
       console.log(resData);
       dispatch({type: SIGNUP});
  
      }
    };`

安慰错误时 Object { "error": Object { "code": 400, "errors": Array [ Object { "domain": "global", "message": "INVALID_EMAIL", "reason": "invalid", }, ], "message": "INVALID_EMAIL", }, }

提前致谢!!

0 个答案:

没有答案