Json 如何读取/解析Firebase Response.createUserWithEmailAndPassword

Json 如何读取/解析Firebase Response.createUserWithEmailAndPassword,json,react-native,parsing,react-redux,firebase-authentication,Json,React Native,Parsing,React Redux,Firebase Authentication,我收到firebase的回复,但不确定如何检索。当我console.log()响应时,我得到[object object],当我JSON.stringify()响应时,我得到的是一些不太有用的东西{“\u 40:0,”\u 65:0,“\u 55:null,”\u 72:null} 我可以在终端中看到firebase的响应:可能未处理的承诺拒绝(id:0):[错误:电子邮件地址已被另一个帐户使用。].这很有帮助,但我不确定如何将其写入我的代码中 const signUp = (dispatch

我收到firebase的回复,但不确定如何检索。当我console.log()响应时,我得到[object object],当我JSON.stringify()响应时,我得到的是一些不太有用的东西
{“\u 40:0,”\u 65:0,“\u 55:null,”\u 72:null}

我可以在终端中看到firebase的响应:
可能未处理的承诺拒绝(id:0):[错误:电子邮件地址已被另一个帐户使用。].
这很有帮助,但我不确定如何将其写入我的代码中

const signUp  = (dispatch) => {
    return  async ({userData})=>{
        try{
            const user = {
                userName: 'test4@test.com',
                password: 'password4'
            };

            //creates user with firebase API
            const response = config.createUser(
                user
            );
            await AsyncStorage.setItem('token', response.__________); 
            dispatch({type: 'sign_up', payload: response.__________});
        } catch(e){
            dispatch({type: 'add_error', payload: 'Something went wrong with sign up'});
        }
    };
};
返回的对象中有令牌,我尝试了多种方法来获取
response.data.apiKey
response.data.stsTokenManager.accessToken
…但运气不好

Object {
  "apiKey": "Aaskjdfj;lkar9V0",
  "appName": "[DEFAULT]",
  "authDomain": "test.firebaseapp.com",
  "createdAt": "1571092641959",
  "displayName": null,
  "email": "test6@test.com",
  "emailVerified": false,
  "isAnonymous": false,
  "lastLoginAt": "1571092641959",
  "phoneNumber": null,
  "photoURL": null,
  "providerData": Array [
    Object {
      "displayName": null,
      "email": "test6@test.com",
      "phoneNumber": null,
      "photoURL": null,
      "providerId": "password",
      "uid": "test6@test.com",
    },
  ],
  "redirectEventId": null,
  "stsTokenManager": Object {
    "accessToken": "eyas;lkdjf;lakfj4TQ",
    "apiKey": "AIzlaskjdf;klajsdfklfnXr9V0",
    "expirationTime": 1571170025283,
    "refreshToken": "AEusjkdfkl;ajsf;kljawSg",
  },
  "tenantId": null,
  "uid": "zU4rhnTnKoNGLlu3gctP2zLorhB2",
}
config.js文件:

createUser = async (user) => {
    console.log('user.email and pw: ' + user.userName + user.password);
    await firebase
    .auth()
    .createUserWithEmailAndPassword(user.userName, user.password)
    .then(console.log(firebase.auth().currentUser));
};

在我看来,您可能希望从
createUser
返回由生成的对象

然后您可以在调用函数中使用它:

try {
    const userCrediential = await config.createUser(user);
}
catch (error) {
    // deal with the error here if the user account already exists
}

并对文档中显示的属性执行任何操作。catch块将从拒绝的承诺中获得错误,这样您就可以知道下一步要做什么。

除了Dougs answer,调用后不能有.then()。函数完成后,似乎只能有一个回调。

请编辑问题以显示实际调用createUserWithEmailAndPassword的代码。我希望看到一个处理返回承诺的调用。@DougStevenson我添加了调用createUserWithEmailAndPasswordI的配置文件,该文件也缺少wait关键字,因此console.logs在响应返回之前运行。谢谢你,这很有帮助!
try {
    const userCrediential = await config.createUser(user);
}
catch (error) {
    // deal with the error here if the user account already exists
}