使用createUserWithEmailAndPassword后获取未定义的ID

时间:2019-01-22 16:37:16

标签: firebase react-native

使用createUserWithEmailAndPassword函数后,我得到未定义的ID。

代码如下:

return async (dispatch) => {
                    dispatch({ type: ATTEMPTING });
                    if(name && email && password)
                    {
                        try {
                         await firebase.auth().createUserWithEmailAndPassword(email, password)
                         .then(user => handleAccountCreated(dispatch, user.uid, name,email,radio))
                        .catch(error => handleError(dispatch, error.message));
                    }catch(e) {
                        handleError(dispatch, e.message);
                    }
                    }else{
                        handleError(dispatch, "There is an error in your data");
                    }


                 }

const handleAccountCreated = (dispatch, userId, name,email , radio) => {
        const ip = '223';
    firebase.database().ref(`mydatabase/${userId}`)
    .set({ name ,email,ip,radio})
    .then(() => { dispatch({ type: SIGNUP_SUCCESS }); })
    .catch(error => handleError(dispatch, error.message));

 }

我已经尝试过:

firebase.auth().createUserWithEmailAndPassword(email, password)

        .then(firebase.auth().onAuthStateChanged( user => handleAccountCreated(dispatch, user.uid, name, email ,radio)))

同一个问题

0 个答案:

没有答案