Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

84
Views
Race condition in ApolloProvider when using multiple clients with different authorizations

I am using ApolloProvider with two authorizations, one for guests and the other for signed-in users. The default client is with the guest authorization and on sign-in, I create a new client with special specific tokens. However, queries that require user authorizations I make soon after sometimes return 401 Permission Denied error. How can I ensure I am using the correct client for my query?

Here is some sample code:

const CustomApolloProvider = ({ children }) => {
  const [client, setClient] = useState(getGuestClient());

  // gets called when user signs in
  const onUserSignIn = () => {
    setClient(getUserClient());
  });

  return <ApolloProvider client={client}>{children}</ApolloProvider>;
};

Another file that throws an error:

const [
  checkUserExists, // needs special permissions
  {
    data: checkUserExistsData,
    loading: loadingCheckUserExistsData,
    error: checkUserExistsError,
    },
] = useLazyQuery(gql(getUser), { fetchPolicy: 'network-only' });

// gets called when user signs in
const onUserSignIn = () => {
  await checkUserExists();
});
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!