authRef .currentUser .updateEmail(newEmail) .then(() => { this.setState({ success: true, working: false }); }, error => { this.setState({ error: error.message, working: false }); });
const createUser = ({email, password}) => { return (dispatch) => { dispatch({type: CREATE_USER}); firebase.auth().createUserWithEmailAndPassword(email, password) .then((user) => loginUserSuccess(dispatch, user)) .catch(() => createUserFail(dispatch)); } }
const saveEmployee = ({name, phone, shift, uid}) => { const {currentUser} = firebase.auth(); return (dispatch) => { firebase.database().ref(`/users/${currentUser.uid}/employees/${uid}`) .set({name, phone, shift}) .then(() => { dispatch({type: SAVE_EMPLOYEE_SUCCESS}); Actions.employeeList({type: 'reset'}); }); //TODO catch error } }
const setSessionFromApi = (session) => { return getUserFromApi(session.email) .then((user) => { const session = setSession({ ...session, ...user }); return { ...session } }); }
componentDidMount() { // Verify the password reset code is valid. authRef .verifyPasswordResetCode(this.props.actionCode) .then(email => { this.setState({ email, validCode: true, verifiedCode: true }); }, error => { // Invalid or expired action code. Ask user to try to reset the password // again. this.setState({ error: error.message, validCode: false, verifiedCode: true }); }); }
const deleteEmployee = ({uid}) => { const {currentUser} = firebase.auth(); return () => { firebase.database().ref(`/users/${currentUser.uid}/employees/${uid}`) .remove() .then(() => { Actions.employeeList({type: 'reset'}); }); //TODO catch error }; }
authRef .sendPasswordResetEmail(email) .then(() => { this.setState({ formSent: true, working: false }); }, error => { this.setState({ error: error.message, working: false }); });
// You might also want to give the user the option to reset their password // in case the account was compromised: authRef .sendPasswordResetEmail(this.state.restoredEmail) .then(() => { // Password reset confirmation sent. Ask user to check their email. this.setState({ resetSent: true }); });
firebase.auth().signOut().then(() => { navigator.pop(); }, function (error) { // An error happened. });
authRef .createUserWithEmailAndPassword(email, password) .then(() => { browserHistory.push('/home') }, error => { this.setState({ error: error.message, working: false }); });
authRef .currentUser .updatePassword(newPassword) .then(() => { this.setState({ success: true, working: false }); }, error => { this.setState({ error: error.message, working: false }); });
authRef .signInWithEmailAndPassword(email, password) .then(() => { browserHistory.push('/home'); }, error => { this.setState({ error: error.message, working: false }); });