nicolaslopezj / meteor-apollo-accounts

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

Huge delay between when you call loginWithPassword and user object becomes available in context? react-native + apollo 2.0 #82

Closed acomito closed 6 years ago

acomito commented 6 years ago

Has anyone seen this behavior? No idea what to do.

If I refresh the react-native app, the next calls will have the user in the context, so loginWithPassword is running, but it doesn't seem to be complete by the time I get a promise back on the client from loginWithPassword.

@nicolaslopezj is this essentially deprecated for apollo 2.0? @joncursi have you set this up with 2.0?

acomito commented 6 years ago

I had a setup like this:

// get the login token (if it exists) and add it to the context (like middleware/header setting globally)

let token;

const withToken = setContext(async request => {
  if (!token){
      token = await AsyncStorage.getItem('Meteor.loginToken')
   }
  return {
    headers: {
      'meteor-login-token': token || null,
    }
  };
});

and my login token would always be out of date, so now I'm just grabbing the token fresh every time until I figure a better way to check if it's already available.

// get the login token (if it exists) and add it to the context (like middleware/header setting globally)

let token;

const withToken = setContext(async request => {
  token = await AsyncStorage.getItem('Meteor.loginToken')
  return {
    headers: {
      'meteor-login-token': token || null,
    }
  };
});