Skip to content

This repository implements full JWT-based authentication using Node.js, Express, and TypeScript. It provides features for user registration πŸ“, activation βœ…, login πŸ”‘, access token refresh πŸ”„, password reset πŸ”, and more. Authentication and route protection are handled through JSON Web Tokens (JWT) πŸ›‘οΈ, offering a secure and scalable solut

Notifications You must be signed in to change notification settings

deepak-raaaz/express-jwt-auth

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

3 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

JWT Authentication API with Node.js, Express, and TypeScript

Node.js Express Typescript JWT

About The Project

This repository implements full JWT-based authentication using Node.js, Express, and TypeScript. It provides features for user registration, activation, login, access token refresh, password reset, and more. Authentication and route protection are handled through JSON Web Tokens (JWT), offering a secure and scalable solution.

Key Features:

  • User Registration with Email Activation
  • Login and Logout
  • JWT-based Access Token and Refresh Token Mechanism
  • Password Reset via Email
  • User Info and Profile Update
  • Secure Routes with JWT Authentication Middleware

Routes Overview

Method Endpoint Description Auth Required
POST /registration Registers a new user No
POST /activate-user Activates a newly registered user No
POST /login Logs in a user No
GET /logout Logs out a user Yes
GET /refresh Refreshes the access token No
GET /me Fetches user information Yes
PUT /update-user-info Updates the user’s information Yes
PUT /change-password Changes the user’s password Yes
POST /reset-password-link Sends a password reset link to the user No
POST /reset-password/:id/:token Resets the user’s password using token No

Built With

This project was developed using the following technologies:

  • Node.js
  • Express.js
  • TypeScript
  • JWT
  • MongoDB
  • Mongoose
  • Nodemailer
  • Cloudinary

Getting Started

Prerequisites

Ensure you have the following installed on your machine:

Installation

  1. Clone the repository:

    git clone https://github.com/deepak-raaaz/express-jwt-auth.git
    cd jwt-auth
  2. Install the dependencies:

    npm install
  3. Create a .env file in the root directory and add the following:

    PORT=8080
    ORIGIN=['http://localhost:8080/']
    NODE_ENV=development
    DB_URL=your_db_url
    CLOUD_NAME=your_cloud_name
    CLOUD_API_KEY=your_cloud_api_key
    CLOUD_SECRET_KEY=your_cloud_secret_key
    REDIS_URL=your_redis_url
    ACTIVATION_SECRET=your_activation_secret_code
    ACCESS_TOKEN=your_access_token
    REFRESH_TOKEN=your_refresh_token
    ACCESS_TOKEN_EXPIRE=5
    REFRESH_TOKEN_EXPIRE=60
    SMTP_HOST=your_smtp_host
    SMTP_PORT=your_smtp_port
    SMTP_USER=your_smtp_user
    SMTP_PASS=your_smtp_password
  4. Build the project:

    npm run build
  5. Start the server:

    npm run start

Usage

Running in Development Mode

You can run the project in development mode using the following command:

npm run dev

This will use ts-node-dev for live reload and faster development.

API Testing

Use tools like Postman or cURL to test the API endpoints. Make sure to provide valid JWT tokens for protected routes.

Example Request (Login)

POST /login
Content-Type: application/json

{
  "email": "[email protected]",
  "password": "password123"
}

Example Request (Protected Route)

GET /me
Authorization: Bearer <access-token>

Contributing

Contributions are welcome! Here's how you can help:

  1. Fork the repository.
  2. Create a feature branch (git checkout -b feature/AmazingFeature).
  3. Commit your changes (git commit -m 'Add some AmazingFeature').
  4. Push to the branch (git push origin feature/AmazingFeature).
  5. Open a pull request.

License

Distributed under the ISC License. See LICENSE for more information.

Contact

Deepak Kumar - [email protected]

GitHub: https://github.com/deepak-raaaz

(back to top)

About

This repository implements full JWT-based authentication using Node.js, Express, and TypeScript. It provides features for user registration πŸ“, activation βœ…, login πŸ”‘, access token refresh πŸ”„, password reset πŸ”, and more. Authentication and route protection are handled through JSON Web Tokens (JWT) πŸ›‘οΈ, offering a secure and scalable solut

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published