Asmaller example of next-auth-example
One of the simplest Next.js (AppRouter) + NextAuth.js template with Tailwind CSS and TypeScript.
SessionProvider from next-auth/react is used to manage the session on the client side. It provides a useSession (from next-auth/react also) hook to access the session object.
middleware protects the routes that need authentication. It is used to check if the user is authenticated or not. If the user is not authenticated, it will redirect the user to the login page. All you need to do is to set callbacks with auth middleware.
To get session data, all you need to do is to const session = await auth() and you will get the session object if session?.user is not null.
You should set the callback url on dev as follows:
http://localhost:3000/auth/callback/auth0