1.0.1 • Published 3 years ago

node-jwt-authentication v1.0.1

Weekly downloads
-
License
ISC
Repository
-
Last release
3 years ago

node-jwt-authentication

node-jwt-authentication is a node.js package for providing jwt authentication in node.js applications.

Installation

npm i node-jwt-authentication

Usage

  1. Signup
const { signup } = require('node-jwt-authentication');
// Then inside async function
try {
        const { user, token } = await signup({ User, secret, email, password });
        console.log(user,token);
    }
catch(err){
        console.log(err);
    }
  1. Login
const { login } = require('node-jwt-authentication');
// Then inside async function
try {
        const { user, token } = await signup({ User, secret, email, password });
        console.log(user,token);
    }
catch(err){
        console.log(err);
    }
  1. Verify Token
const { verifyToken } = require('node-jwt-authentication');

try {
        const { id } = await verifyToken(token, secret);
        console.log(id);
  }
catch (err){
        console.log(err);
  }

Functions

  • signup({model,secret,email,password}): Takes the model, secret for jwt encoding, email and password of the user, saves the new user to db by hashing password and then returns the user and jwt token.

  • login({model,secret,email,password}): Takes the model, secret for jwt encoding, email and password of the user, authenticates the user and then returns the user and jwt token.

  • verifyToken(token,secret): Takes the jwt token and secret used for jwt encoding and then returns the id of the user.