Comments (9)
Besides, atob is a browser API and not a JS API, and by providing a userland implementation this library would remove the browser dependency.
It might not be part of the ECMAScript specification, but it is also widely supported by most other JavaScript run-times (e.g. Node.js, Bun and Deno). However, if there are many React Native users that need it this is something we might have to reconsider adding back in.
Personally, I think it might not be worth it to add back a polyfill for this. But we should perhaps update the README with instructions specifically for React Native users to include a polyfill to help them out.
I've also logged an issue with the Hermes runtime that is used by React Native to evaluate support (see facebook/hermes#1178). I would recommend that you chime in there and let your voice be heard.
from jwt-decode.
We removed the atob()
polyfill under #162, as this is a widely supported function in browsers and Node.js. I don't think we'd want to add back a polyfill and bloat the library just for React Native. Have you tried poly-filling this function using something like core-js
?
For example:
import "core-js/stable/atob";
import { jwtDecode } from "jwt-decode";
const token = "eyJ0eXAiO.../// jwt token";
const decoded = jwtDecode(token);
console.log(decoded);
from jwt-decode.
Thanks to the fast work from the Hermes team support for these functions has landed, and should ship in the latest version of Hermes that will be released soon (likely 0.74).
from jwt-decode.
Good news, the Hermes team has decided to implement this functionality, so polyfilling these APIs should no longer be needed in the future for React Native (see facebook/hermes#1178 (comment)).
from jwt-decode.
For anyone looking for HOW to polyfill
first do
yarn add base-64
then at the top of your index.js add these lines
import { decode } from 'base-64';
global.atob = decode;
from jwt-decode.
I could polyfill this function, however I think react-native has got a lot of users, and it would be nice if this library provided a way to work without it. Besides, atob is a browser API and not a JS API, and by providing a userland implementation this library would remove the browser dependency.
However, I understand your stance on the matter, and respect your decision.
from jwt-decode.
Thanks for reaching out. jwt-decode
had always been a browser-focussed library, which happened to work on node or other platforms as well because of the atob polyfill.
This is also called out in the repository's description:
Decode JWT tokens; useful for browser applications.
However, as atob is supported in node, we also explicitly support node without a polyfill now.
As of v4, any platform that has no access to atob, should rely on their own polyfill such as core-js as mentioned by @jonkoops.
The reason we no longer ship an atob polyfill is because the majority has support for atob (see browser support and node support), and those that do not can use a polyfill. We believe we do not want to ship the polyfill to all our users, knowing that the majority has no need for this in the first place.
So long story short, nothing should prevent you from using this library in react-native, but you will need to bring in your own atob polyfill.
Feel free to reach out if using the core-js polyfill wouldn't work, but closing this for now.
from jwt-decode.
@iusama46 , there is no need to downgrade to v3. Instead add the polyfill as mentioned in the readme.
However, once the Hermes team has released the changes for atob, you should no longer need the polyfill.
from jwt-decode.
Downgrade jwt-decode to 3.1.2
from jwt-decode.
Related Issues (20)
- Thoughts on adding a bin? HOT 3
- Two additional tests? HOT 4
- jwtDecode is not a function HOT 3
- Does not work with electron packager/asar archive HOT 5
- ESM Support with Jest for Node Api clients HOT 2
- How about removing the atob polyfill? HOT 8
- Consider renaming `master` branch to `main` HOT 2
- Type definitions are broken in 4.0.0-beta.1 HOT 10
- Consider dropping Universal Module Definition (UMD) bundle HOT 4
- Yarn installing jwt-decode causes nx Daemon to crash HOT 4
- Using jwt-decode beta with node10 module resolution HOT 8
- InvalidTokenError: Invalid token specified: Unexpected number at position 0 HOT 3
- missing: https://unpkg.com/[email protected]/build/jwt-decode.js HOT 3
- No Support for React Native & Expo HOT 2
- Compatibility Issue with Node.js 16.18.1 on Expo Application Servers HOT 2
- React native decode HOT 1
- InvalidTokenError HOT 3
- jwt decode is not working in react native HOT 2
- jwtDecode is not working react native app HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jwt-decode.