5

I have an application where a user can sign up for an event. As soon as the user has signed up, he can visit routes he couldn't before.

I'm using graphql for my api requests. The code in my route guard looks like this:

router.beforeEach(async (to, from, next) => {
  if (to.meta.signUpRequired && from.name) {
    const { data: { getCurrentUser } } 
      = await apolloProvider.defaultClient.query({
      query: USER_INFO_QUERY
    });
    if (getCurrentUser && getCurrentUser.isCollectionAttendee) {
      return next();
    }
    return next('/');
  }
  return next();
});

This works fine and the request is not executed every time the route changes because vue-apollo caches the result. My problem is, that if the user signs up and then tries to switch the route, he can't because the cached result of the query is still used.

I don't want to use a network-only fetchPolicy before every route change.

How can I solve this?

Timo Jokinen
  • 707
  • 7
  • 26

1 Answers1

0

Maybe try using this.$apolloProvider.defaultClient.resetStore() after sign-up.