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

119
Visualizações
Is calling auth0 hook to verify authentication in all my Custom React Hook a good approach?

I have a single-page app where I build multiples Custom React Hook to fetch data in my backend (MongoDB). Every time, I'm also verifying if the user is logged before fetching data like so:

export const useTotalSessionsToday = () => {
  const { user } = useAuth0();
  let userName;
  if (user) {
    userName = user.name;
  }

  const { data, loading, error } = useQuery(GET_TOTAL_SESSIONS_TODAY, {
    variables: { userName },
  });

  return { data, loading, error };
};

Currently, I'm calling the auth0 hook in every Custom Hook. I find it hard to believe there isn't a better way (since calling auth0 hook is somehow slow).

Should I use localStorage and store the user "username" on page load and then fetch it from there instead? Or is it still better to call auth0 every time?

PS: I use Typescript with React and Graphql

about 4 years ago · Santiago Gelvez
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