
Build a secure, standard MERN stack user authentication system with JWT, using React, Tailwind, Node.js, and MongoDB, including password hashing, email verification, and password reset flows.
Set up a React application for the MERN stack authentication project by creating a client folder with create-react-app, starting the dev server on localhost:3000, and updating src.
Install Tailwind in a React app, generate tailwind.config.js and postcss.config.js, and update the index.css to enable Tailwind styles and verify with Tailwind IntelliSense.
Learn tailwind basics by building a flex layout, centering content with justify-center and items-center, applying height and text utilities, and styling buttons and inputs with borders, padding, and spacing.
Install essential npm modules such as react-router-dom, axios, and react-hot-toast, set up a pages and components folder, and configure routes for home, login, and register before starting the dev server.
Build a MERN stack login and register UI with a simple centered white form, capturing email, password, and confirm password using useState, and applying initial front-end and back-end logic.
Covers managing registration form states (name, email), duplicating them for login, styling with tailwind theming using primary and secondary colors, and wiring onChange and onClick handlers for authentication.
Set up the back end and folder structure, initialize npm, install express, mongoose, jsonwebtoken, bcrypt, and crypto, and create an express server on port 5000 with a hello route.
Explore setting up a robust backend folder structure for a MERN authentication system, configure MongoDB Atlas with a connection string, and implement JWT authentication and middleware.
Establish a MongoDB connection in Node.js with mongoose by centralizing credentials in a data file and importing them, then configure mongoose.connect with use new url parser and log success.
Build basic login and registration APIs using express and mongoose, create a user model with name, email, password and is_verified default false, and handle 200/400 responses for registration and login.
Connect React and Node.js to integrate frontend and backend, test login and registration APIs, configure a proxy to run on localhost 5000, and prepare for password hashing with MongoDB.
Implement login and register flows with loading indicators and toast messages that show loading, success, or error states, including network error handling and something went wrong alerts.
Master the backend duplicate email check during user registration, returning clear errors when a user already exists, and implement password encryption and decryption for secure authentication.
Explain password hashing during user registration with bcrypt in a MERN stack app, generating salt and hashing the password before saving the hashed value to the database.
Learn to verify user passwords by comparing the plaintext login input with the encrypted password stored in MongoDB, handling user existence and login outcomes, with salt-aware decryption.
Implement JWT authentication to secure a private route by issuing and validating tokens, contrasting with plain authentication stored in local storage that exposes user details and lacks authorization.
Implement a backend JWT workflow that signs encrypted user data into a token that expires in 60 minutes, then send token to the client and verify it on protected routes.
Implement public and protected routes in a MERN auth system using a single token stored in local storage; guard the home page and redirect unauthenticated users to login.
Send a jwt from the frontend to the backend, verify it, and fetch user info with axios using a bearer header, redirecting to login on error.
Implement a jwt validation middleware that extracts the bearer token from the authorization header, verifies it, and attaches the user to the request.
Demonstrates sending email verification with nodemailer in a Node.js backend, configuring a transporter and a reusable send email utility for registration and password reset workflows.
Document how to configure node mailer with Gmail using app passwords and two-factor verification, enabling an admin account to send verification and password emails in a MERN authentication setup.
Implement email verification by creating a token model, generating encrypted tokens tied to a user, and sending a verification link. Validate and delete the token upon verification.
Develop the email verification flow by implementing a backend verify email endpoint, validating the token, updating the user as verified, and deleting the token after success.
MERN is one of several variations of the MEAN stack (MongoDB Express Angular Node), where the traditional Angular.js frontend framework is replaced with React.js. Other variants include MEVN (MongoDB, Express, Vue, Node), and any front-end JavaScript framework that can work.
MongoDB - document database
Express(.js) - Node.js web framework
React(.js) - a client-side JavaScript framework
Node(.js) - the premier JavaScript web server
Authentication is the act of proving an assertion, such as the identity of a computer system user. In contrast with identification, the act of indicating a person or thing's identity, authentication is the process of verifying that identity.
Authorization specifies access rights/privileges to resources, which is related to general information security and computer security, and access control in particular. More formally, "to authorize" is to define an access policy
In this course, we will learn the following topics
Basic Authentication
Password hashing / encryption / decryption
Email verification functionality
Forgot password functionality
JWT authentications
Working with Protected Routes and Public Routes
Handling API requests with auth middlewares
React is a free and open-source front-end JavaScript library for building user interfaces based on UI components. It is maintained by Meta and a community of individual developers and companies.
Node.js is an open-source, cross-platform, back-end JavaScript runtime environment that runs on the V8 engine and executes JavaScript code outside a web browser.