Giter Club home page Giter Club logo

Comments (9)

jonkoops avatar jonkoops commented on June 3, 2024 4

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.

jonkoops avatar jonkoops commented on June 3, 2024 3

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.

jonkoops avatar jonkoops commented on June 3, 2024 3

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.

jonkoops avatar jonkoops commented on June 3, 2024 2

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.

ShepSims avatar ShepSims commented on June 3, 2024 2

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.

hrastnik avatar hrastnik commented on June 3, 2024 1

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.

frederikprijck avatar frederikprijck commented on June 3, 2024 1

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.

frederikprijck avatar frederikprijck commented on June 3, 2024 1

@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.

iusama46 avatar iusama46 commented on June 3, 2024

Downgrade jwt-decode to 3.1.2

from jwt-decode.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.