Skip to content

wpcodevo/JWT_Authentication_React

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Node.js + TypeScript + MongoDB: JWT Authentication

In this article, you'll learn how to add JSON Web Token (JWT) Authentication to your Node.js app with TypeScript, MongoDB, Mongoose, Typegoose, Docker, Redis, and Zod.

Node.js + TypeScript + MongoDB: JWT Authentication

Topics Covered

  • Setup Development Environment (Optional)
    • Download and Install Node.js
    • Download and Install Docker
    • Download and Install MongoDB Compass
  • Node.js, Redis, MongoDB, Typegoose, Docker: JWT Authentication example
  • JWT Authentication Flow with Redis, MongoDB, and Node.js
  • Project Structure
  • Project Setup
    • Initialize a Node.js Project with TypeScript
    • Install the Required Libraries
    • Initialize and Start the Express Server
    • Setting up Redis and MongoDB with Docker Compose
    • Connecting to the MongoDB Docker Container with Mongoose
    • Connecting to Redis Docker Container
  • Creating the Database Schema with Typegoose
  • How to Generate Private and Public keys for JWT Authentication
  • Define Middleware to Sign and Verify JWTs
  • Define a Custom Error Handler in Express
  • Define the Zod Validation Schema
  • Create a Middleware to Validate the User Inputs
  • Create a Service to Communicate with the Database
  • Create the Authentication Controller
  • Create the User Controller to Test Authorization
  • Define a function to deserialize the User
  • Define a function to check if the user is logged in
  • Define a Middleware to Restrict Unauthorized Access
  • Create the Authentication Routes
  • Update the app.ts file to use the route
  • Testing the JWT Authentication Rest API
    • Register users
    • Login user
    • Get Currently Logged in User's Credentials
    • Admin Get All Users

Read the entire article here: https://codevoweb.com/node-typescript-mongodb-jwt-authentication/

Articles in this series:

1. Node.js + TypeScript + MongoDB: JWT Authentication

Node.js + TypeScript + MongoDB: JWT Authentication

2. Node.js + TypeScript + MongoDB: JWT Refresh Token

Node.js + TypeScript + MongoDB: JWT Refresh Token

3. Google OAuth Authentication with React.js and Node.js (No Passport)

Google OAuth Authentication with React.js and Node.js (No Passport)

4. GitHub OAuth Authentication React.js and Node.js(No Passport)

GitHub OAuth Authentication React.js and Node.js(No Passport)

About

JWT Authentication and Authorization with React, RTK Query, Material UI, React Hook Form and Zod.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages