Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

85
Visualizações
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
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda