Introduction
Next.js has become a preferred framework for modern web applications due to its simplicity and flexibility. One key aspect of any application is user authentication, and integrating GitHub login into a Next.js project is a practical choice. In this guide, we’ll walk through setting up a Next.js project with GitHub authentication using Auth.js, breaking it down into clear, actionable steps.
Whether you’re a beginner or an experienced developer, this guide will help you configure authentication seamlessly.
Step 1: Setting Up Your Next.js Project
First, we need to create a new Next.js project. Follow these steps:
- Open your terminal and run the following command:
npx create-next-app@latest
- You will be prompted to configure your project. Here’s an example of how to answer these questions:
What is your project named?my-app
Would you like to use TypeScript?YesorNo(your choice)
Would you like to use ESLint?YesorNo
Would you like to use Tailwind CSS?YesorNo
Would you like your code inside asrc/directory?YesorNo
Would you like to use App Router?Yes(recommended)
Would you like to use Turbopack fornext dev?NoorYes(your preference)
Customize the import alias? You can set it to@/*or leave it as default.
- Once complete, navigate to your project directory:
cd my-app
Step 2: Install Auth.js
To manage authentication, we’ll use Auth.js (formerly known as NextAuth.js). Install it with the following command:
npm install next-auth@beta
Step 3: Configure Auth.js
to treat me to a virtual coffee. Cheers!
SOCIAL SHARE CARD GENERATOR