Skip to content

Commit

Permalink
Merge pull request #16 from krutoo/readme-upd
Browse files Browse the repository at this point in the history
readme-upd
  • Loading branch information
krutoo authored Oct 15, 2024
2 parents 4e79340 + 1c8e58a commit 33d2cbd
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,35 @@ 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<string | null>
token: () => getJwtFromSomewhere(),
})
),
);
```

### `proxy`

Returns simple proxy middleware. Useful for servers based on Fetch API.
Expand Down

0 comments on commit 33d2cbd

Please sign in to comment.