New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

authilize

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

authilize

Library for authentication middleware using JWT

latest
Source
npmnpm
Version
1.0.2
Version published
Maintainers
1
Created
Source

Introduction

Library for authentication middleware using JWT

Code Samples

Initialize Authilize instance

const router = require("express").Router();
const { postController } = require("../controllers/controller");

const { isAuth, isAuthPass } = require("Authilize");

// POST
router.post("/", isAuth, postController);
router.post("/", isAuthPass, postController);

module.exports = router;

Controller example

exports.postController = async (req, res, next) => {
  const { username, email } = req.decodedData // Get your data from req.decodedData.
  return res.status(200).json({ message: "successful" });
};

You can customize it as you like
if not then the status code will be 401 by default and error message will be "Unauthorized Access"
.env (VARIABLES MUST BE THE SAME)

AUTHILIZE_JWT_SECRET_KEY = Fdjjfklsdjfklasf
AUTHILIZE_STATUS_CODE = 401
AUTHILIZE_ERR_MESSAGE = Unauthorized Access

If you are using isAuthPass and the token is invalid or not passed in the headers then req.decodedData will be undefined

List of functions

FunctionsDescription
isAuthFunction which checks if the user is authorized (retrieves bearer token from req)
isAuthPassFunction which checks if the user is authorized (retrieves bearer token from req)

List of variables

FunctionsDescriptionDefault
AUTHILIZE_JWT_SECRET_KEYrequired (only for isAuth)
AUTHILIZE_STATUS_CODEoptional401
AUTHILIZE_ERR_MESSAGEoptional"Unauthorized Access"

Installation

NPM:

npm install authilize

Yarn:

yarn add authilize

Keywords

auth

FAQs

Package last updated on 27 May 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts