React Native Firebase:被捕获的auth / user-not-found没有与此标识符相对应的用户记录。用户可能已被删除

时间:2018-07-04 18:46:13

标签: javascript firebase react-native firebase-authentication

caught auth/user-not-found There is no user record corresponding to this identifier. The user may have been deleted.

关于使用电子邮件和密码登录Firebase,似乎在从saga换成使用时,即

this.props.dispatch({
    type: 'API_LOADING'
});

function* watchSignin(action) {
    const { email, password } = action;

    try {
        yield put({type: 'API_LOADING'});

        let response = yield call(API.signin, email, password);

        if (response) {
            if (response.error) {
                yield call(Actions.genericModal, { modalType: 'error', description: response.error.message });
            } else if (response.user) {
                const { uid, email, emailVerified } = response.user;
                const profile = response.user;
                const idToken = response.idToken;

                if (emailVerified) {
                    // Load profile into state
                    yield put({type: 'API_SIGNIN_SUCCESSFUL', profile: profile, idToken: idToken});

                    // Save session into local cache
                    yield call(LocalCache.setProfile, profile);
                    yield call(LocalCache.setToken, idToken);

                    yield call(Actions.homeScreen);
                } else {
                    response = yield call(API.requestVerificationEmail);
                    yield call(Actions.genericModal, { modalType: 'error', description: I18n.t('modal.error.messages.email_verified_validation_error') });
                }
            } else {
                yield call(Actions.genericModal, { modalType: 'error' });
            }
        } else {
            yield call(Actions.genericModal, { modalType: 'error', description: I18n.t('modal.error.messages.connection_validation_error') });
        }
    } catch (err) {
        yield call(Actions.genericModal, { modalType: 'error' });
    }

    yield put({type: 'API_LOADED'});


}

export async function signin(email, password) {
    return await firebase.auth().signInWithEmailAndPassword(email, password)
    .then(user => {
        let currentUser = firebase.auth().currentUser; // Get current firebase user after sign in.

        return currentUser.getIdToken() // Get idToken for server-side verification of requests.
        .then(idToken => {
            return { user: currentUser, idToken: idToken }; // return current user and token.
        })
        .catch((err) => { // Catch errors i.e. status codes and messages such as auth errors.
            let error = err;
            return { error: err };
        })
        return { user: currentUser, idToken: null }; // Return currrent user without auth token.
    })
    .catch((err) => { // Caught errors returned with error code and message.
        console.log('caught', err.code, err.message);
        let error = err;
        return { error: err };
    });
}

使用动作,即

handleSubmit =异步()=> {     const {电子邮件,密码} = this.state;

if (!(email && password)) {    
    Actions.genericModal({ modalType: 'error', description: I18n.t('modal.error.messages.sign_up_validation_error') });                
    return false;
}

// this.props.setLoading();
this.props.signIn(email, password);

}

export const signIn = (email, password) => async (dispatch) => {
  try {
    await firebase.auth().signInWithEmailAndPassword(email, password)
    .then(user => {
        let currentUser = firebase.auth().currentUser; // Get current firebase user after sign in.
        console.log('current', currentUser);
        currentUser.getIdToken(true) // Get idToken for server-side verification of requests.
        .then(idToken => {
            dispatch({ type: AUTH_SIGNIN_SUCCESS, profile: currentUser, idToken: idToken });
            // return { user: currentUser, idToken: idToken }; // return current user and token.
        })
        .catch((err) => { // Catch errors i.e. status codes and messages such as auth errors.
          dispatch({ type: AUTH_SIGNIN_FAILURE, message: err.message || 'Something went wrong during signin.' });
        })
    })
    .catch((err) => { // Caught errors returned with error code and message.
        console.log('caught', err.code, err.message);
        dispatch({ type: AUTH_SIGNIN_FAILURE, message: err.message || 'Something went wrong during signin.' });
    });
  } catch(err) {
    console.log(err);
    dispatch({ type: AUTH_SIGNIN_FAILURE, message: err.message || 'Something went wrong during signin.' });
  }
}

我收到以下错误响应

`caught auth/user-not-found There is no user record corresponding to this identifier. The user may have been deleted.`

尽管使用佐贺时我没有得到这个。用户确实确实存在,并且这适用于传奇方法而不适用于动作方法。

有人可以告诉我我的代码有什么问题吗,可能是什么原因造成的?

非常感谢您的帮助:)

更新 看来,通过致电

firebase.auth().createUserWithEmailAndPassword(email, password).catch(function(error) {
  // Handle Errors here.
  var errorCode = error.code;
  var errorMessage = error.message;
  // ...
});

然后在.then的{​​{1}}内进行createUserWithEmailAndPassword,但我不确定为什么仍然如此。

0 个答案:

没有答案