nextjs-auth0-starter icon indicating copy to clipboard operation
nextjs-auth0-starter copied to clipboard

How to avoid the boilerplate for auth check?

Open 9bits opened this issue 4 years ago • 0 comments

Thanks for the tutorial!

I'm currently struggling to create a template that can be shared by all pages so I don't have to write the auth boilerplate everytime. Is there a way around it?

https://github.com/CaptainChemist/nextjs-auth0-starter/blob/master/pages/profile.tsx#L15-L26

Having to write this all the time will be extremely tedious

  const { user, loading } = useFetchUser();

  if (loading) {
    return (
      <MainLayout>
        <p>Loading...</p>
      </MainLayout>
    );
  }
  if (!user && !loading) {
    Router.replace('/');
  }

9bits avatar May 14 '20 06:05 9bits