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

115
Views
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
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!