Sheetbase Module: @sheetbase/api-key
Sheetbase middleware to authorize with the API Key.
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
-
Docs homepage: https://sheetbase.github.io/api-key
-
API reference: https://sheetbase.github.io/api-key/api
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.