@fundamend/pages-plugin-verify-jwt
v0.0.7
Published
_pages-plugin-verify-jwt_ is a [Cloudflare Pages plugin] used by the [fundamend.dev] ecosystem. It offers a [middleware] for verifying [JWT]s with a verification key.
Downloads
4
Readme
pages-plugin-verify-jwt
pages-plugin-verify-jwt is a Cloudflare Pages plugin used by the fundamend.dev ecosystem. It offers a middleware for verifying JWTs with a verification key.
Installation
Use your favorite Node.js package manager, for example npm, like so:
npm install --save @fundamend/pages-plugin-verify-jwt
... or yarn, like so:
yarn add @fundamend/pages-plugin-verify-jwt
Usage
Add a _middleware.js
file where you want to verify JWTs, import pages-plugin-verify-jwt and call it on a request, like so:
import verifyJWTPlugin from "@fundamend/pages-plugin-verify-jwt";
export const onRequest = verifyJWTPlugin();
The plugin expects an environment variable of the name JWT_VERIFICATION_KEY
to be set in Cloudflare.
Create this variable in the Cloudflare Dashboard or with wrangler (for local testing use a .dev.vars
file) and set it to the verification key of your JWT token.
The plugin will be executed on every request inside the _middleware.js
file's path.
If the JWT verifies with the JWT_VERIFICATION_KEY
, it calls the next Cloudflare Pages function or middleware.
If not, it returns a 401 - Unauthorized
response.