Coder Social home page Coder Social logo

codetit4n / node-jwt-auth-template-ts Goto Github PK

View Code? Open in Web Editor NEW
6.0 2.0 1.0 187 KB

Basic template you can use in your Node Backends for JWT authentication - TypeScript edition. Uses Node.js, Express.js and MongoDB.

License: MIT License

TypeScript 99.39% Shell 0.61%
express node ready-to-use mongodb authentication backend-api hashedpassword jwt-authentication jwt-bearer-tokens protected-routes

node-jwt-auth-template-ts's Introduction

JWT authentication template for Node Backend - TypeScript edition

Basic template you can use in your projects for JWT authentication. It is built using Node.js, Express.js and MongoDB. It has amazing Type Security which is possible because of TypeScript.

Routes:

/api/user/register - POST

Creates a new user. It takes name, email and password in the request body and stores the name, email and hashed password in the Mongo database.

/api/user/login - POST

Logs in the registered user and sends a new signed JWT. This JWT can be stored in local storage, etc.

/api/protected - GET

Simple protected route, just for testing the JWT. You will need a valid JWT to access this route. Put the JWT in the header like: Authorization: 'Bearer [JWT]'

How to use this template:

  1. Clone the repo using:
git clone https://github.com/codeTIT4N/node-jwt-auth-template-ts
  1. Rename .env.example to .env

  2. Update the .env file with project secrets like:

  3. Go inside the project and run the following commands:

npm install
npm run build
npm start
  1. Edit the src/routes/protected.ts file for the protected routes according to your project's needs. One example is provided in this file.

  2. Edit the src/controllers/protected.ts file for the controllers that will be executed after JWT validation. One example is provided in this file.

  3. To compile TypeScript code to JavaScript and see the changes in real time, in a different terminal instance, run:

tsc -w

node-jwt-auth-template-ts's People

Contributors

codetit4n avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  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.