Giter Site home page Giter Site logo

jwt-nodejs's Introduction

JWT Authentication with Express and Node

This is a simple Node.js and Express application demonstrating JWT (JSON Web Token) authentication. The application includes user login functionality, token generation, and a protected route that requires a valid JWT for access.

Installation

  1. Clone this repository.

    git clone https://github.com/spm999/JWT-Nodejs.git
    
    

Installation

  1. Navigate to the project directory.

    cd JWT-Nodejs
  2. Install dependencies.

    npm install

Usage

  1. Start the server.

    npm start
  2. Access the server at http://localhost:3000.

Endpoints

User Login

  • URL: /login
  • Method: POST
  • Description: Allows users to log in and obtain a JWT token.
  • Request Body: Should include a JSON object with username and password.
  • Response: Returns a JWT token if the login is successful.

Protected Route

  • URL: /protected
  • Method: GET
  • Description: A protected route that requires a valid JWT for access.
  • Authorization Header: Should include a Bearer token obtained during login.
  • Response: Returns a message indicating successful access to the protected route if the token is valid.

JWT Authentication

The application uses a simple in-memory user database and a secret key for JWT signature. In a real-world scenario, replace the in-memory database with a proper database, and keep the secret key secure.

Contributing

Feel free to contribute to this project by opening issues or submitting pull requests.

jwt-nodejs's People

Contributors

spm999 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.