I have the following simple saga in my react-native app:
import {call, put, take} from 'redux-saga/effects';
import firebase from 'react-native-firebase';
export function* signupWithEmailPassword(action: AuthAction) {
const {email, password} = action.payload;
try {
const user = yield call(doRegister, email, password);
yield put({type: 'SIGNUP_SUCCESS', payload: user});
} catch (error) {
yield put({type: 'SIGNUP_FAILURE', error});
}
}
function* doRegister(email: string, password: string) {
return firebase.auth().createUserAndRetrieveDataWithEmailAndPassword(email, password)
.catch((error) => {
const {code, message} = error;
console.log('in doRegister: error ' + code + ' - ' + message);
});
}
if the saga gets called with an invalid email, then firebase will throw an error like 'auth/invalid-email'. That's fine and expected, but for some reason yield call(doRegister, email, password);
is not failing and therefore yield put({type: 'SIGNUP_SUCCESS', payload: user});
is called even though it should fall back to the catch
.
what am I doing wrong?
edit:
changing doRegister
to this, causes the same issues:
function* doRegister(email: string, password: string) {
return firebase.auth().createUserAndRetrieveDataWithEmailAndPassword(email, password);
}