nicolaslopezj / meteor-apollo-accounts

Meteor accounts in GraphQL
MIT License
146 stars 37 forks source link

Getting odd "unhandled promise rejection" errors with react-native on android. #55

Closed acomito closed 7 years ago

acomito commented 7 years ago

The same code seems to work fine when I run the app on an iphone 7, but getting errors on my galaxy s6. I thought maybe I needed to add .done() to the promise after reading this:

https://github.com/facebook/react-native/issues/6925

but .done() is undefined.

I'm not really sure what is going on. Everything works on iOS. My own mutations/queries are all working on android and talking to the server other than the meteor-apollo-accounts. I'm wondering if maybe it has something to do with the Async storage setup? I'm confused because I have a catch in place.

acomito commented 7 years ago

I'm finding that userId() is still working but I get the unhandled promise issue on loginWithPassword, logout and createUser. Again it works fine on my iphone 7 so I'm not sure exactly whats up with android (s6). I've ended up doing this sketchy setup for the time being:

this.setState({loading: true});

try {
        const id = await loginWithPassword({ email: this.state.email.trim(), password: this.state.password.trim() }, apollo)

        // on iphone this code will run, as you would expect
        apollo.resetStore();
        this.setState({loading: false});
        return this.props.navigation.navigate('main');
    } 

catch (err) {

        // on android, the user will be logged in 
        // but an error is getting thrown and the stack trace is esoteric, 
        // so I check here to see if they're on android, then if the userId exists
       //  then move them into the app as if no error was thrown

        if (Platform.OS === 'android') {
          if(await userId()){
            apollo.resetStore();
            this.setState({loading: false});
            return this.props.navigation.navigate('main');
          } 
        }

        // if the userId does not exist and they aren't on android,
        // I dont move them forward and display errors in the UI

        let errors = err && err.graphQLErrors && err.graphQLErrors.length > 0 && err.graphQLErrors.map( err => err.message );
        this.setState({loading: false, errors: errors});
        return console.log('error ran')
    }
sabativi commented 7 years ago

I am experiecing the same issue... and do not really like this... @acomito did you come up with a better solution ?

acomito commented 7 years ago

@sabativi no... I wish community would help @nicolaslopezj build up this package. We can't expect him to do all of it himself for free. If apollo team wants adoption by meteor community, this package is a must.

sabativi commented 7 years ago

Indeed, my problem is that I do not know how to reproduce this bug. It seems to be random when I test it, furthermore, it only happens on fresh installation app... I can help on this, as I really depends on this package for my mobile app.