Skip to content

Commit

Permalink
Update README
Browse files Browse the repository at this point in the history
  • Loading branch information
frederikprijck committed Jul 22, 2023
1 parent bd23aaf commit 30c65e2
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
![Browser library that helps decoding JWT tokens which are Base64Url encoded](https://cdn.auth0.com/website/sdks/banners/jwt-decode-banner.png)

**IMPORTANT:** This library doesn't validate the token, any well formed JWT can be decoded. You should validate the token in your server-side logic by using something like [express-jwt](https://github.com/auth0/express-jwt), [koa-jwt](https://github.com/stiang/koa-jwt), [Owin Bearer JWT](https://github.com/michaelnoonan/Auth0-Owin-JwtBearerAuthentication), etc.
**IMPORTANT:** This library doesn't validate the token, any well-formed JWT can be decoded. You should validate the token in your server-side logic by using something like [express-jwt](https://github.com/auth0/express-jwt), [koa-jwt](https://github.com/stiang/koa-jwt), [Microsoft.AspNetCore.Authentication.JwtBearer](https://www.nuget.org/packages/Microsoft.AspNetCore.Authentication.JwtBearer), etc.

![Release](https://img.shields.io/npm/v/jwt-decode)
![Downloads](https://img.shields.io/npm/dw/jwt-decode)
Expand Down Expand Up @@ -71,15 +71,16 @@ Not adhering to the format will result in a `InvalidTokenError` with one of the

#### Use with typescript

The `jwt_decode` function will return an `unknown` type by default. You can specify what the expected return type should be by passing a type argument to the `jwt_decode` function.
The return type of the `jwt_decode` function is determined by the `header` property of the object passed as the second argument. If omitted (or set to false), it'll use `JwtPayload`, when true it will use `JwtHeader`.
If needed, you can specify what the expected return type should be by passing a type argument to the `jwt_decode` function.

The package also exports types for a `JwtHeader` and `JwtPayload` with some default claims. You can either use them as-is, or extend them to include non standard claims or properties.
If needed, you can extend both `JwtHeader` and `JwtPayload` to include non-standard claims or properties.

```typescript
import jwtDecode, { JwtPayload } from "jwt-decode";
import jwtDecode from "jwt-decode";

const token: string = "eyJhsw5c";
const decoded = jwtDecode<JwtPayload>(token); // Returns with the JwtPayload type
const decoded = jwtDecode(token); // Returns with the JwtPayload type
```

#### Use as a CommonJS package
Expand All @@ -91,7 +92,7 @@ const jwt_decode = require('jwt-decode');

#### Include with a script tag

Copy the file `jwt-decode.js` from the `build/` folder to your project somewhere, then include like so:
Copy the file `jwt-decode.js` from the `dist/` folder to your project somewhere, then include like so:

```html
<script src="jwt-decode.js"></script>
Expand Down

0 comments on commit 30c65e2

Please sign in to comment.