meteor-apollo-accounts icon indicating copy to clipboard operation
meteor-apollo-accounts copied to clipboard

Logout is not working

Open nimish-gupta opened this issue 7 years ago • 5 comments

Graphql Error: Cannot read property "userId" of null http://www.awesomescreenshot.com/image/2472459/bb6c0baa15bdd8884caf8abed11d387f

nimish-gupta avatar May 08 '17 22:05 nimish-gupta

Maybe that example is not up to date?

nicolaslopezj avatar May 09 '17 23:05 nicolaslopezj

I have git cloned the version and update all the packages

nimish-gupta avatar May 10 '17 13:05 nimish-gupta

@nimishrocks Since this example, another initialization for GraphQL schema has been implemented which is incompatible with the one in the example (without tweaking a bit). Can you share your GraphQL initialization? And client implementation ?

dbrrt avatar May 14 '17 23:05 dbrrt

Can anyone confirm this bug?

nicolaslopezj avatar Aug 09 '17 05:08 nicolaslopezj

I have a userId issue on logout. I added Accounts.onLogout hook on the server like this:

Accounts.onLogout(({ user, connection }) => {
  console.log({ user, connection });
  /* other code */
});

And when I call logout on the client I've got user === undefined sometimes.

I think I found the root of the issue. When I modify library code that way (see comments), everything becomes fine:

async function(apollo) {
  const token = await getLoginToken()

  if (!token) return

  await apollo.mutate({ // wait for apollo mutate
    mutation: gql`
      mutation logout($token: String!) {
        logout(token: $token) {
          success
        }
      }
    `,
    variables: {
      token
    }
  })
  await resetStore() // move this line afret apollo.mutate
}

The reason of that behaviour is that Meteor listens for localStorage on the client and when resetStore happens before apollo mutation, Meteor logs out on the client and resolver's context doesn't contain userId anymore when mutation order comes.

Reversing the order prevents this.

@nicolaslopezj Could please you fix the issue with code modification similar to the above?

nikogosovd avatar Aug 17 '18 08:08 nikogosovd