【发布时间】:2020-02-12 13:15:18
【问题描述】:
我收到了来自 firebase 的回复,但不确定如何检索它。当我 console.log() 得到响应时,我得到 [object Object] 而当我 JSON.stringify() 得到响应时,我得到的东西不太有用{"_40":0,"_65":0,"_55":null,"_72":null}
我可以在终端中看到来自 firebase 的回复:Possible Unhandled Promise Rejection (id: 0):[Error: The email address is already in use by another account.]. 这很有帮助,但我不知道如何将其放入我的代码中。
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));
};
【问题讨论】:
-
请编辑问题以显示实际调用 createUserWithEmailAndPassword 的代码。我希望看到一个处理它返回的承诺的调用。
-
@DougStevenson 我添加了调用 createUserWithEmailAndPassword 的配置文件
标签: json react-native parsing react-redux firebase-authentication