meteor-apollo-accounts
meteor-apollo-accounts copied to clipboard
Logout is not working
Graphql Error: Cannot read property "userId" of null http://www.awesomescreenshot.com/image/2472459/bb6c0baa15bdd8884caf8abed11d387f
Maybe that example is not up to date?
I have git cloned the version and update all the packages
@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 ?
Can anyone confirm this bug?
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?