SocketCluster/socketcluster-client

global atob btoa not available in JavaScriptCore and react-native

Closed this issue ยท 4 comments

Getting this exception when running a react-native project on device:

global.atob is not a function

Most likely due to this line:

decodedToken = global.atob(encodedTokenData);

Perhaps the solution is to use a polyfill like https://github.com/mathiasbynens/base64 to supplement these methods when running socketcluster-client in a more restricted runtime like JavaScriptCore.

Verified works with base-64 (don't forget the dash!)
For react-native googlers, npm i --save base-64, then add this somewhere in your codebase and make sure it runs before socketcluster-client is referenced:

if (!global.atob) {
  global.atob = require('base-64').decode;
}

@sjmueller Ok, that should be fixed in v4.1.6.

Confirmed! Thanks @jondubois!

Thanks @sjmueller, it worked for me ๐Ÿ‘