Secure Next - Js Applications With Role-Based Authentication Using NextAuth
Secure Next - Js Applications With Role-Based Authentication Using NextAuth
Beau Carnes
https://www.freecodecamp.org/news/secure-next-js-applications-with-role-based-authentication-using-nextauth/ 1/3
12/1/24, 12:20 PM Secure Next.js Applications with Role-Based Authentication Using NextAuth
If you create Next.js apps, chanced are you are going to have to include user authentication
at some point.
We just posted a course on the freeCodeCamp.org YouTube channel that teaches how to
implement authentication in Next.js 13.5 with the powerful library, NextAuth – which will soon
be known as AuthJS.
Jacob Lower from Clarity Coders created this course. He is an experienced developer and
teacher.
https://www.freecodecamp.org/news/secure-next-js-applications-with-role-based-authentication-using-nextauth/ 2/3
12/1/24, 12:20 PM Secure Next.js Applications with Role-Based Authentication Using NextAuth
The course kicks off with the basics of NextAuth, walking you through the environment setup
and project creation. Then you will learn how to use NextAuth for server-rendered and client-
rendered pages, giving you a holistic understanding of authentication processes.
The tutorial takes a practical approach by incorporating out-of-the-box OAuth providers such
as Google and GitHub, showing you how to integrate these widely used services into your
application seamlessly. But for those who like to customize, the course has got you covered
too. It explores how to craft your custom authentication provider using MongoDB, ensuring
you know how to tailor authentication to your specific requirements.
This video is not just about the 'how-to' but also about the 'how-it-works.' From setting up API
routes and options to protecting pages on both the server and client side, the course is
structured to provide you with hands-on experience. You'll even learn about middleware and
how to manage login and logout functionalities effectively.
Introduction
Environment Setup / Extension Review
Project Creation
Install NextAuth (Auth.js) / Create Project Structure
Create NextAuth (Auth.js) API - Options / Routes
Setup built-in OAuth Provider - (Google / GitHub)
Login / Logout Funtionality
Protecting Pages - Server Side Page
Protecting Pages - Client Side Page
Protecting Pages - Middleware
Creating Custom Provider (Creating a Database of Users)
MongoDB Atlas Signup / Setup
Create User Models (Mongoose Schema)
User Form to Create Users
Create Users API
Setup Custom Provider
Watch the full course on the freeCodeCamp.org YouTube channel (1.5-hour watch).
https://www.freecodecamp.org/news/secure-next-js-applications-with-role-based-authentication-using-nextauth/ 3/3