diff --git a/README.md b/README.md
index d51f9fd..94ed863 100644
--- a/README.md
+++ b/README.md
@@ -36,7 +36,7 @@ async () => {
return
// Decoding token
- const payload = jwt.decode(token)
+ const { payload } = jwt.decode(token)
}
```
@@ -62,15 +62,20 @@ async () => {
return
// Decoding token
- const payload = jwt.decode(token) // { name: 'John Doe', email: 'john.doe@gmail.com', ... }
+ const { payload } = jwt.decode(token) // { name: 'John Doe', email: 'john.doe@gmail.com', ... }
}
```
## Usage
+- [Sign](#sign)
+- [Verify](#verify)
+- [Decode](#decode)
+
-### `jwt.sign(payload, secret, [options])`
+### Sign
+#### `jwt.sign(payload, secret, [options])`
Signs a payload and returns the token.
@@ -87,7 +92,8 @@ Returns token as a `string`.
-### `jwt.verify(token, secret, [options])`
+### Verify
+#### `jwt.verify(token, secret, [options])`
Verifies the integrity of the token and returns a boolean value.
@@ -102,7 +108,8 @@ Returns `true` if signature, `nbf` (if set) and `exp` (if set) are valid, otherw
-### `jwt.decode(token)`
+### Decode
+#### `jwt.decode(token)`
Returns the payload **without** verifying the integrity of the token. Please use `jwt.verify()` first to keep your application secure!
@@ -111,7 +118,19 @@ Argument | Type | Satus | Default | Description
`token` | `string` | required | - | The token string generated by `jwt.sign()`.
#### `return`
-Returns payload `object`.
+Returns an `object` containing `header` and `payload`:
+```javascript
+{
+ header: {
+ alg: 'HS256',
+ typ: 'JWT'
+ },
+ payload: {
+ name: 'John Doe',
+ email: 'john.doe@gmail.com'
+ }
+}
+```
### Available Algorithms
- ES256
diff --git a/index.d.ts b/index.d.ts
index 4018ce3..9f0c07c 100644
--- a/index.d.ts
+++ b/index.d.ts
@@ -33,9 +33,9 @@ declare class JWT {
* Returns the payload **without** verifying the integrity of the token. Please use `jwt.verify()` first to keep your application secure!
*
* @param {string} token The token string generated by `jwt.sign()`.
- * @returns {object | null} Returns payload `object`.
+ * @returns {JWTDecodeReturn} Returns an `object` containing `header` and `payload`.
*/
- decode(token: string): object | null
+ decode(token: string): JWTDecodeReturn
}
declare const _exports: JWT
@@ -52,4 +52,9 @@ type JWTVerifyOptions = {
throwError?: boolean
}
+type JWTDecodeReturn = {
+ header: object,
+ payload: object
+}
+
export = _exports
\ No newline at end of file