Skip to content

AlexDevToAI/DevPro_backend

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

JWT authentication for Node Backend - 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

About

This is devPro backend in 2024

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •