From 4c5a9dd7b4483bd4c04a71e66b2264a39e58782e Mon Sep 17 00:00:00 2001 From: Frederik Prijck Date: Mon, 30 Oct 2023 11:19:51 +0100 Subject: [PATCH 1/8] Add README instructions for polyfilling atob --- README.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/README.md b/README.md index dc4ce06..b42b142 100644 --- a/README.md +++ b/README.md @@ -53,6 +53,20 @@ console.log(decodedHeader); **Note:** A falsy or malformed token will throw an `InvalidTokenError` error; see below for more information on specific errors. +## Polyfilling atob + +This library relies on `atob()`, which is a global function available on [all modern browsers as well as every supported node environment](https://developer.mozilla.org/en-US/docs/Web/API/atob#browser_compatibility). + +In order to use `jwt-decode` in an environment that has no access to `atob()` (e.g. React Native), ensure to provide the corresponding polyfill in your application: + +```js +import "core-js/stable/atob"; +import { jwtDecode } from "jwt-decode"; + +const token = "eyJ0eXAiO.../// jwt token"; +const decoded = jwtDecode(token); +``` + ## Errors This library works with valid JSON web tokens. The basic format of these token is From fe873ab2f0f7e0c88e0af855710332828319355d Mon Sep 17 00:00:00 2001 From: Frederik Prijck Date: Mon, 30 Oct 2023 14:07:47 +0100 Subject: [PATCH 2/8] Update README.md --- README.md | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index b42b142..c467070 100644 --- a/README.md +++ b/README.md @@ -57,14 +57,18 @@ console.log(decodedHeader); This library relies on `atob()`, which is a global function available on [all modern browsers as well as every supported node environment](https://developer.mozilla.org/en-US/docs/Web/API/atob#browser_compatibility). -In order to use `jwt-decode` in an environment that has no access to `atob()` (e.g. React Native), ensure to provide the corresponding polyfill in your application: +In order to use `jwt-decode` in an environment that has no access to `atob()`, ensure to provide the corresponding polyfill in your application: ```js import "core-js/stable/atob"; -import { jwtDecode } from "jwt-decode"; +``` -const token = "eyJ0eXAiO.../// jwt token"; -const decoded = jwtDecode(token); +Some environments might not work well with polyfills and require you to import the pure function and expose it yourself instead (e.g. React Native): + +``` +import atob from "core-js-pure/stable/atob"; + +global.atob = atob; ``` ## Errors From a5dbb0ec1fb5bcaa52c8fa7db483a7020407001a Mon Sep 17 00:00:00 2001 From: Frederik Prijck Date: Mon, 30 Oct 2023 14:08:41 +0100 Subject: [PATCH 3/8] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index c467070..4f6fbae 100644 --- a/README.md +++ b/README.md @@ -65,7 +65,7 @@ import "core-js/stable/atob"; Some environments might not work well with polyfills and require you to import the pure function and expose it yourself instead (e.g. React Native): -``` +```js import atob from "core-js-pure/stable/atob"; global.atob = atob; From 4d4b319d8bd7461223d307b26d90cb2b01878589 Mon Sep 17 00:00:00 2001 From: Frederik Prijck Date: Mon, 13 Nov 2023 09:33:55 +0100 Subject: [PATCH 4/8] Update README.md --- README.md | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 4f6fbae..ebe7b5f 100644 --- a/README.md +++ b/README.md @@ -57,18 +57,17 @@ console.log(decodedHeader); This library relies on `atob()`, which is a global function available on [all modern browsers as well as every supported node environment](https://developer.mozilla.org/en-US/docs/Web/API/atob#browser_compatibility). -In order to use `jwt-decode` in an environment that has no access to `atob()`, ensure to provide the corresponding polyfill in your application: +In order to use `jwt-decode` in an environment that has no access to `atob()`, ensure to provide the corresponding polyfill in your application by using [`core-js/stable/atob`](https://www.npmjs.com/package/core-js): ```js import "core-js/stable/atob"; ``` -Some environments might not work well with polyfills and require you to import the pure function and expose it yourself instead (e.g. React Native): +Alternatively, you can also use [`base-64`](https://www.npmjs.com/package/base-64) and polyfill `global.atob` yourself: ```js -import atob from "core-js-pure/stable/atob"; - -global.atob = atob; +import { decode } from 'base-64'; +global.atob = decode; ``` ## Errors From 4507e79875a595d0d448e7fdb56dcb1b8a5134d4 Mon Sep 17 00:00:00 2001 From: Frederik Prijck Date: Mon, 13 Nov 2023 09:35:35 +0100 Subject: [PATCH 5/8] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index ebe7b5f..57313c1 100644 --- a/README.md +++ b/README.md @@ -57,7 +57,7 @@ console.log(decodedHeader); This library relies on `atob()`, which is a global function available on [all modern browsers as well as every supported node environment](https://developer.mozilla.org/en-US/docs/Web/API/atob#browser_compatibility). -In order to use `jwt-decode` in an environment that has no access to `atob()`, ensure to provide the corresponding polyfill in your application by using [`core-js/stable/atob`](https://www.npmjs.com/package/core-js): +In order to use `jwt-decode` in an environment that has no access to `atob()` (e.g. [React Native](https://github.com/facebook/hermes/issues/1178)), ensure to provide the corresponding polyfill in your application by using [`core-js/stable/atob`](https://www.npmjs.com/package/core-js): ```js import "core-js/stable/atob"; From c295cd702c6d978e111a7d8100e01b945c93bb59 Mon Sep 17 00:00:00 2001 From: Frederik Prijck Date: Mon, 13 Nov 2023 09:36:56 +0100 Subject: [PATCH 6/8] Update README.md --- README.md | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/README.md b/README.md index 57313c1..518d4ad 100644 --- a/README.md +++ b/README.md @@ -57,13 +57,7 @@ console.log(decodedHeader); This library relies on `atob()`, which is a global function available on [all modern browsers as well as every supported node environment](https://developer.mozilla.org/en-US/docs/Web/API/atob#browser_compatibility). -In order to use `jwt-decode` in an environment that has no access to `atob()` (e.g. [React Native](https://github.com/facebook/hermes/issues/1178)), ensure to provide the corresponding polyfill in your application by using [`core-js/stable/atob`](https://www.npmjs.com/package/core-js): - -```js -import "core-js/stable/atob"; -``` - -Alternatively, you can also use [`base-64`](https://www.npmjs.com/package/base-64) and polyfill `global.atob` yourself: +In order to use `jwt-decode` in an environment that has no access to `atob()` (e.g. [React Native](https://github.com/facebook/hermes/issues/1178)), ensure to provide the corresponding polyfill in your application by using [`base-64`](https://www.npmjs.com/package/base-64): ```js import { decode } from 'base-64'; From d72a1f6351f20a041e868f8220f56eae04389ad3 Mon Sep 17 00:00:00 2001 From: Frederik Prijck Date: Mon, 13 Nov 2023 09:52:08 +0100 Subject: [PATCH 7/8] Revert "Update README.md" This reverts commit c295cd702c6d978e111a7d8100e01b945c93bb59. --- README.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 518d4ad..57313c1 100644 --- a/README.md +++ b/README.md @@ -57,7 +57,13 @@ console.log(decodedHeader); This library relies on `atob()`, which is a global function available on [all modern browsers as well as every supported node environment](https://developer.mozilla.org/en-US/docs/Web/API/atob#browser_compatibility). -In order to use `jwt-decode` in an environment that has no access to `atob()` (e.g. [React Native](https://github.com/facebook/hermes/issues/1178)), ensure to provide the corresponding polyfill in your application by using [`base-64`](https://www.npmjs.com/package/base-64): +In order to use `jwt-decode` in an environment that has no access to `atob()` (e.g. [React Native](https://github.com/facebook/hermes/issues/1178)), ensure to provide the corresponding polyfill in your application by using [`core-js/stable/atob`](https://www.npmjs.com/package/core-js): + +```js +import "core-js/stable/atob"; +``` + +Alternatively, you can also use [`base-64`](https://www.npmjs.com/package/base-64) and polyfill `global.atob` yourself: ```js import { decode } from 'base-64'; From 5b6e77b70c223f4d26413484a7da276f56069b44 Mon Sep 17 00:00:00 2001 From: Frederik Prijck Date: Mon, 13 Nov 2023 13:22:11 +0100 Subject: [PATCH 8/8] Update README.md Co-authored-by: Jon Koops --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 57313c1..02f87be 100644 --- a/README.md +++ b/README.md @@ -66,7 +66,7 @@ import "core-js/stable/atob"; Alternatively, you can also use [`base-64`](https://www.npmjs.com/package/base-64) and polyfill `global.atob` yourself: ```js -import { decode } from 'base-64'; +import { decode } from "base-64"; global.atob = decode; ```