Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

91
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda