js-jose icon indicating copy to clipboard operation
js-jose copied to clipboard

Can't find variable: atob (Jose.min.js) for React Native Project

Open wajahatshaw opened this issue 5 years ago • 13 comments

Screen Shot 2019-09-24 at 5 01 51 PM I'm trying to integrate the library inside a react native project and it gives me this issue. Have some tried implementing json web encryption for react native?

wajahatshaw avatar Sep 24 '19 12:09 wajahatshaw

You will need a atob polyfill

rmhrisk avatar Sep 26 '19 00:09 rmhrisk

Does the following help? In some environments (e.g. node), atob/btoa don't exist but you can use Buffer.

function btoa(data) { return new Buffer(data, "binary").toString("base64"); }
function atob(data) { return new Buffer(data, "base64").toString("binary"); }

alokmenghrajani avatar Sep 26 '19 07:09 alokmenghrajani

I have faced this issue and I have not solutions.

MrLich avatar Feb 28 '20 09:02 MrLich

@MrLich does the above snippet now work for you? You just need to have btoa and atob functions be defined in the global scope.

mbyczkowski avatar Feb 29 '20 00:02 mbyczkowski

@MrLich does the above snippet now work for you? You just need to have btoa and atob functions be defined in the global scope.

Thanks, I have solved it by adding more code .

MrLich avatar Feb 29 '20 04:02 MrLich

@MrLich how did you solve? thanks

alerojaslopenza avatar Mar 12 '20 01:03 alerojaslopenza

I had the same problem. I solved it by requiring this polyfill in my project

AregShahbazian avatar Apr 17 '20 02:04 AregShahbazian

I had the same problem and found online the below that I added to my App.js file. It works for me

import {decode, encode} from 'base-64' if (!global.btoa) { global.btoa = encode } if (!global.atob) { global.atob = decode }

md1116 avatar Apr 18 '20 23:04 md1116

I had the same problem and found online the below that I added to my App.js file. It works for me

import {decode, encode} from 'base-64' if (!global.btoa) { global.btoa = encode } if (!global.atob) { global.atob = decode }

it is not working for me

banerbaner avatar May 15 '20 11:05 banerbaner

I had the same problem and found online the below that I added to my App.js file. It works for me import {decode, encode} from 'base-64' if (!global.btoa) { global.btoa = encode } if (!global.atob) { global.atob = decode }

it is not working for me

Abhinavkumar216 avatar May 24 '20 03:05 Abhinavkumar216

Installing the base-64 npm package and then adding the import code above to App.js file solved my issue.

rajasuman09 avatar Jun 08 '20 21:06 rajasuman09

Installing the base-64 npm package and then adding the import code above to App.js file solved my issue.

This solved my problem too!

honhaochen avatar Jun 10 '20 07:06 honhaochen

https://www.npmjs.com/package/@react-native-anywhere/polyfill-base64. helped me. Дапамагло мне

Rubon72 avatar Jan 26 '22 19:01 Rubon72