From 039453fb7e9a39ea908447afb4ee2cd2b08c4a80 Mon Sep 17 00:00:00 2001 From: krutoo Date: Tue, 15 Oct 2024 17:36:04 +0500 Subject: [PATCH 1/2] readme-upd - jwt added to readme --- README.md | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/README.md b/README.md index a90c27b..e7dd539 100644 --- a/README.md +++ b/README.md @@ -140,6 +140,34 @@ const myFetch = configureFetch( ); ``` +### `jwt` + +Returns simplest JWT middleware. This middleware will add `Authorization` header to each request that matches the condition. + +```ts +import { applyMiddleware } from '@krutoo/fetch-tools'; +import { jwt } from '@krutoo/fetch-tools/middleware'; + +const myFetch = configureFetch( + fetch, + applyMiddleware( + jwt({ + // Access token + token: '...', + + // Determines whether to add a header + filter: req => req.url.includes('/api/'), + }) + + // ...or like this + jwt({ + // "token" can be function that should return string or null or Promise + token: () => getJwtFromSomewhere(), + }) + ), +); +``` + ### `proxy` Returns simple proxy middleware. Useful for servers based on Fetch API. From 1c8e58a2cd6533551c64722df6b849619d1948f1 Mon Sep 17 00:00:00 2001 From: krutoo Date: Tue, 15 Oct 2024 17:37:54 +0500 Subject: [PATCH 2/2] readme-upd - fmt --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index e7dd539..60ba9fe 100644 --- a/README.md +++ b/README.md @@ -142,7 +142,8 @@ const myFetch = configureFetch( ### `jwt` -Returns simplest JWT middleware. This middleware will add `Authorization` header to each request that matches the condition. +Returns simplest JWT middleware. This middleware will add `Authorization` header to each request +that matches the condition. ```ts import { applyMiddleware } from '@krutoo/fetch-tools';