@sheetbase/api-key
TypeScript icon, indicating that this package has built-in type declarations

1.2.0 • Public • Published

Sheetbase Module: @sheetbase/api-key

Sheetbase middleware to authorize with the API Key.

Build Status Coverage Status NPM License clasp Support me on Patreon PayPal Ask me anything

Install

Using npm: npm install --save @sheetbase/api-key

import * as ApiKey from "@sheetbase/api-key";

As a library: 1NulS_tPHLm401X7Km_ONKgtRK-VHnC5ODmNZ1sMt0QgXuDgtffxJ-Zzv

Set the Indentifier to ApiKeyModule and select the lastest version, view code.

declare const ApiKeyModule: { ApiKey: any };
const ApiKey = ApiKeyModule.ApiKey;

Usage

Getting started

Install: npm install --save @sheetbase/api-key

import { middleware as apiKeyMiddleware } from "@sheetbase/api-key";

const ApiKeyMiddleware = apiKeyMiddleware({ key: apiKey });

router.get("/", ApiKeyMiddleware, (req, res) => {
  return res.send("Aye!");
});

Configs

key

  • Type: string

A single key.

apiKeys

  • Type: {[key: string]: string | APIKey}

Multiple api keys for multiple clients.

interface APIKey {
  value?: string;
  id?: string;
  title?: string;
  description?: string;
  createdAt?: string | number;
  [k: string]: any;
}

failure

  • Type: (req: RouteRequest, res: RouteResponse) => any (Sheetbase route handler)

Custom handler if not passed, default showing an unauthorized message.

{
  failure: (req, res) => res.json({ hey: "Go away!" });
}

trigger

  • Type: (req: RouteRequest, apiKey: APIKey) => void

Trigger when the middileware is call, useful for logging multiple API keys usage.

{
  trigger: (req, apiKey) => {
    return console.log("A client access using this API Key:", apiKey);
  };
}

License

@sheetbase/api-key is released under the MIT license.

Package Sidebar

Install

npm i @sheetbase/api-key

Weekly Downloads

2

Version

1.2.0

License

MIT

Unpacked Size

27.2 kB

Total Files

17

Last publish

Collaborators

  • lamnhan