diff --git a/README.md b/README.md index 37265f1..15d2616 100644 --- a/README.md +++ b/README.md @@ -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) @@ -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(token); // Returns with the JwtPayload type +const decoded = jwtDecode(token); // Returns with the JwtPayload type ``` #### Use as a CommonJS package @@ -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