Sheetbase middleware to authorize with the API Key.
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;
-
Docs homepage: https://sheetbase.github.io/api-key
-
API reference: https://sheetbase.github.io/api-key/api
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!");
});
- Type:
string
A single key.
- 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;
}
- 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!" });
}
- 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);
};
}
@sheetbase/api-key is released under the MIT license.