1.0.29 • Published 1 year ago

auth-lib-jwt v1.0.29

Weekly downloads
-
License
ISC
Repository
-
Last release
1 year ago

Authentication API Library

Overview

This is a reusable library for implementing authentication functionality in Node.js applications. It provides endpoints for user registration, login, logout, and token management (e.g., generating and refreshing access tokens).

Installation

npm i auth-lib-jwt

Endpints

"/authLibCheck";
"/login";
"/signup";
"/refresh-token";
"/getUser";
"/logout";

Usage

import express from "express";
import helmet from "helmet";
import authLib from "auth-lib-jwt";

// Initialize express app
const app = express();

// Initialize authentication library
authLib.initialize({
  // Implement your own logic for these functions
  getUser: () => ({ success: true }),
  addToken: ({}) => ({ success: true }),
  getToken: () => ({ success: true }),
  saveUser: () => ({ success: true }),
  deleteExistingToken: () => ({ success: true }),
});

// Allow BigInt to be serialized to JSON
BigInt.prototype.toJSON = function () {
  return this.toString();
};

// Middleware
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
app.use(express.static("public"));
app.use(helmet());

// Routes
app.use(
  "/api/Other-api-routers" // Other api routers
);
app.use("/auth", authLib.getRoutes());

// Define port
const port = process.env.PORT || 3000;

// Start server
app.listen(port, () =>
  console.log(`
šŸš€ Server ready at: ${port}`)
);
1.0.22

1 year ago

1.0.26

1 year ago

1.0.25

1 year ago

1.0.24

1 year ago

1.0.23

1 year ago

1.0.29

1 year ago

1.0.28

1 year ago

1.0.27

1 year ago

1.0.19

1 year ago

1.0.18

1 year ago

1.0.17

1 year ago

1.0.16

1 year ago

1.0.21

1 year ago

1.0.20

1 year ago

1.0.15

1 year ago

1.0.14

1 year ago

1.0.13

1 year ago

1.0.12

1 year ago

1.0.11

1 year ago

1.0.10

1 year ago

1.0.9

1 year ago

1.0.8

1 year ago

1.0.7

1 year ago

1.0.6

1 year ago

1.0.5

1 year ago

1.0.4

1 year ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago