This is a simple example of how to protect routes in Next.js using a custom ProtectedRoute.tsx
component.
Note: You could also use
getInitialProps
orgetServerSideProps
to protect routes
-
Clone the repo and
cd
into the directory -
Install dependencies
npm i
- Run the app
npm run dev
- Open http://localhost:3000 with your browser to see the result.