function register(data) {
    return (dispatch) => {
        return new Promise((resolve, reject) => {
            const {email, password, name, username} = data;
            auth.createUserWithEmailAndPassword(email, password)
                .then((resp) => {
                    let user = {name, uid: resp.user.uid, username}
                    const userRef = database.ref().child('users');

                    userRef.child(user.uid).update({...user})
                        .then(() => {
                            dispatch({type: t.LOGGED_IN, user});
                            resolve(user)
                        })
                        .catch((error) => reject({message: error}));
                })
                .catch((error) => reject(error));
        })
    };
}
//Register the user using email and password
Register the user using email and password
Register the user using email and password
function register(data) {
    return (dispatch) => {
        return new Promise((resolve, reject) => {
            const {email, password, name, username} = data;
            auth.createUserWithEmailAndPassword(email, password)
                .then((resp) => {
                    let user = {name, uid: resp.user.uid, username}
                    const userRef = database.ref().child('users');
                    userRef.child(user.uid).update({...user})
                        .then(() => {
                            dispatch({type: t.LOGGED_IN, user});
                            resolve(user)
                        })
                        .catch((error) => reject({message: error}));
                })
                .catch((error) => reject(error));
        })
    };
}
function register ( data ) { return ( dispatch ) => { return new Promise ( ( resolve , reject ) => { const { email , password , name , username } = data ; auth . createUserWithEmailAndPassword ( email , password ) . then ( ( resp ) => { let user = { name , uid : resp . user . uid , username } const userRef = database . ref ( ) . child ( 'users' ) ; userRef . child ( user . uid ) . update ( { ... user } ) . then ( ( ) => { dispatch ( { type : t . LOGGED_IN , user } ) ; resolve ( user ) } ) . catch ( ( error ) => reject ( { message : error } ) ) ; } ) . catch ( ( error ) => reject ( error ) ) ; } ) } ; }
Register the user using email and password
Register the user using email and password