Skip to content

In this tutorial, you will learn how to set up NextAuth v5 in Next.js 14. With the release of NextAuth v5, a couple of breaking changes have been introduced, and getting NextAuth up and running in a Next.js 14 project requires a bit of setup.

Notifications You must be signed in to change notification settings

wpcodevo/nextauth-nextjs14-prisma

Repository files navigation

1. Setup and Use NextAuth.js in Next.js 14 App Directory

In this tutorial, you will learn how to set up NextAuth v5 in Next.js 14. With the release of NextAuth v5, a couple of breaking changes have been introduced, and getting NextAuth up and running in a Next.js 14 project requires a bit of setup.

Setup and Use NextAuth.js in Next.js 14 App Directory

Topics Covered

  • How to Run the Next.js Application on Your Machine
  • Bootstrap the Next.js 14 Project
  • Install the Required Dependencies
  • Initialize NextAuth.js in Next.js 14
  • Set up Prisma for Database Interactions
    • Set up PostgreSQL with Docker
    • Set up Prisma and Prisma Client
  • Hack Around the Account Registration
  • Implement Credentials Authentication
  • Implement Google and GitHub OAuth
  • Three Ways of Fetching the NextAuth Session Data
    • Retrieving the Session in a React Server Component
    • Retrieving the Session in an API Route
    • Retrieving the Session in a React Client Component
  • How to Add Custom Data to the Session Data
  • Three Ways of Protecting Routes with NextAuth
    • Client-Side Route Protection
    • Server-Side Route Protection
    • Middleware Route Protection
  • Creating a Custom Registration Page
    • Create the Account Registration API Route
    • Create the Form Component
    • Create the Page Component
  • Conclusion

Read the entire article here: https://codevoweb.com/setup-and-use-nextauth-in-nextjs-14-app-directory/

2. Implement Authentication with NextAuth in Next.js 14

In this tutorial, you'll discover how to set up NextAuth v5 in Next.js 14, configure Prisma ORM for database interactions, implement user registration and login, and secure routes using Next.js middleware with NextAuth.

Implement Authentication with NextAuth in Next.js 14

Topics Covered

  • Running the Project on Your Computer
  • Demo of the Authentication Flow
  • Configuring Tailwind CSS
  • Setting up a PostgreSQL Server with Docker Compose
  • Creating Prisma Models for NextAuth
  • Initializing NextAuth.js in Next.js 14
  • Implementing Credentials Authentication with NextAuth
  • Creating a Header Component
  • Creating Zod Validation Schemas
  • Implementing Account Registration
    • Creating the Account Registration API Route
    • Creating the Account Registration Form
    • Creating the Page Component
  • Implementing User Sign-in with NextAuth
    • Creating the Account Login Form
    • Creating the Page Component
  • Protecting Routes with NextAuth Middleware
  • Creating a Protected Page
  • Conclusion

Read the entire article here: https://codevoweb.com/implement-authentication-with-nextauth-in-nextjs-14/

3. Set up Google and GitHub OAuth with NextAuth in Next.js 14

In this comprehensive guide, you will learn how to set up Google and GitHub OAuth with NextAuth v5 in your Next.js 14 project. Incorporating OAuth sign-in options into your application can eliminate the need for users to sign in with their email and password.

Set up Google and GitHub OAuth with NextAuth in Next.js 14

Topics Covered

  • How to Run the Project on Your Computer
  • Demo of the OAuth Flow
  • Obtaining Google and GitHub OAuth Credentials
    • Google OAuth Client ID and Secret
    • GitHub OAuth Client ID and Secret
  • Initializing NextAuth.js in Next.js 14
  • Adding Google and GitHub Providers to NextAuth
  • Modifying the JWT Payload and Session Data
  • Implementing Google and GitHub OAuth Sign-in Options
  • Protecting Routes with NextAuth Middleware
  • Conclusion

Read the entire article here: https://codevoweb.com/google-and-github-oauth-with-nextauth-in-nextjs-14/

About

In this tutorial, you will learn how to set up NextAuth v5 in Next.js 14. With the release of NextAuth v5, a couple of breaking changes have been introduced, and getting NextAuth up and running in a Next.js 14 project requires a bit of setup.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published