Thanks to visit codestin.com
Credit goes to github.com

Skip to content

nirangad/is-authenticated

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

is-authenticated

Simple middleware for Express to validate JSON web token

Install

npm i @nirangad/is-authenticated

Usage

Make sure to set SECRET_KEY environment variable which used to be passed to jwt.verify as jwt.Secret or jwt.GetPublicKeyOrSecret

Setting environment variable

# In .env file
SECRET_KEY="SECRET_KEY"

Preparing the JWT token

import jwt from "jsonwebtoken";

...

const token = jwt.sign(
  {
    id: user.id,
    email: user.email,
    timestamp: Date.now()
  },
  process.env.SECRET_KEY,
  {
    expiresIn: "10h"
  }
);

Using isAuthenticate in Express endpoint

import isAuthenticated from "@nirangad/is-authenticated";

# Express Routes
app.get("/product", isAuthenticated, (req, res) => {
  return res.json({ status: 1, message: "Welcome to Product Service" });
});

About

Simple middleware for Express to validate JSON web token

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published