You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -69,35 +69,50 @@ Not adhering to the format will result in a `InvalidTokenError` with one of the
69
69
-`Invalid token specified: invalid base64 for part #` => the part could not be base64 decoded (the message should contain the error the base64 decoder gave)
70
70
-`Invalid token specified: invalid json for part #` => the part was correctly base64 decoded, however, the decoded value was not valid JSON (the message should contain the error the JSON parser gave)
71
71
72
-
#### Use with typescript
72
+
#### Use with TypeScript
73
73
74
-
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`.
75
-
If needed, you can specify what the expected return type should be by passing a type argument to the `jwt_decode` function.
74
+
The return type of the `jwtDecode` 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`.
75
+
If needed, you can specify what the expected return type should be by passing a type argument to the `jwtDecode` function.
76
76
77
77
You can extend both `JwtHeader` and `JwtPayload` to include non-standard claims or properties.
78
78
79
79
```typescript
80
-
importjwtDecodefrom"jwt-decode";
80
+
import{ jwtDecode }from"jwt-decode";
81
81
82
-
const token:string="eyJhsw5c";
82
+
const token ="eyJhsw5c";
83
83
const decoded =jwtDecode<JwtPayload>(token); // Returns with the JwtPayload type
84
84
```
85
85
86
86
#### Use as a CommonJS package
87
87
88
88
```javascript
89
-
constjwt_decode=require('jwt-decode');
89
+
const{ jwtDecode }=require('jwt-decode');
90
90
...
91
91
```
92
92
93
93
#### Include with a script tag
94
94
95
-
Copy the file `jwt-decode.js` from the `build/` folder to your project somewhere, then include it like so:
95
+
Copy the file `jwt-decode.js` from the root of the `build/` folder to your project somewhere, then include it like so:
96
96
97
97
```html
98
98
<scriptsrc="jwt-decode.js"></script>
99
99
```
100
100
101
+
Once this script has loaded, the `jwt_decode` function will be exposed as a global:
102
+
103
+
```javascript
104
+
consttoken="eyJhsw5c";
105
+
constdecoded=jwt_decode(token);
106
+
```
107
+
108
+
Alternatively, if you are using the [Asynchronous Module Definition (AMD) API](https://github.com/amdjs/amdjs-api/blob/master/AMD.md), you can load the same function as follows:
0 commit comments