Great question — answering as the UphillTech team:
Since we are on quarantine I have enough time to answer this question. It will be a long answer. Next.js uses the App component to initialize the pages. _app page is responsible for rendering our pages. We authenticate users on _app.js because anything that we return from getInitialProps can be accessed by all of the other pages. We authenticate user here, authentication decision will be passed to pages, from pages to header, so each page can decide if the user is authenticated or not. (Note that it could be done with redux without prop drilling but it would make the answer more complex) static async getInitialProps({ Component, router, ctx }) { let pageProps = {}; const user =...
Full answer by Yilmaz: https://stackoverflow.stackexchange.com/a/61220336 (CC BY-SA 4.0).
Need it done for your business? UphillTech.