Next-Auth in App Router of Next.js

Rohit Kumar
5 min readJun 27, 2023

If you are not memeber of the medium.com, read here for free

Next.js has recently released a stable version of App Router enriched with in-built support for layouts, templates, routing, loading, and error handling.

The current version of Next-Auth documentation is published with examples of the Page Router of Next.js. This document share approach to setting up Next.js with the Next-Auth App Router.

What is covered in this document?

  1. Setup of Next.js app with app router.
  2. Install Next-Auth.
  3. Configuration of Github Provider.
  4. Add Handler for Next-Auth
  5. Sign in and Sign out using next-auth.
  6. Session in API Routes
  7. Use session in the Server Components
  8. Use of session in the Client Components.

1. Set up the Next.js app with the App router.

Follow this document to create a basic next.js app with an app router.

Next.js app with App router.

2. Install Next-Auth

--

--