diff --git a/dev-client/index.js b/dev-client/index.js index 4f03e6e82..a54380c8c 100644 --- a/dev-client/index.js +++ b/dev-client/index.js @@ -1,7 +1,7 @@ /** * @format */ - +import 'terraso-mobile-client/prelude'; import {AppRegistry} from 'react-native'; import App from 'terraso-mobile-client/App'; import {name as appName} from './app.json'; // eslint-disable-line @typescript-eslint/no-restricted-imports diff --git a/dev-client/package-lock.json b/dev-client/package-lock.json index bb2f28ae3..3369651a3 100644 --- a/dev-client/package-lock.json +++ b/dev-client/package-lock.json @@ -15,6 +15,7 @@ "@react-navigation/native": "^6.1.9", "@react-navigation/native-stack": "^6.9.16", "@rnmapbox/maps": "^10.0.15", + "base-64": "^1.0.0", "formik": "^2.4.5", "i18next": "^23.6.0", "native-base": "^3.4.28", @@ -45,6 +46,7 @@ "@babel/runtime": "^7.23.2", "@react-native-community/eslint-config": "^3.2.0", "@tsconfig/react-native": "^3.0.2", + "@types/base-64": "^1.0.1", "@types/jest": "^29.5.6", "@types/react": "^18.2.33", "@types/react-native-vector-icons": "^6.4.16", @@ -7269,6 +7271,12 @@ "@babel/types": "^7.20.7" } }, + "node_modules/@types/base-64": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/@types/base-64/-/base-64-1.0.1.tgz", + "integrity": "sha512-syGYQWNlO2yyGJjyP9i3eZeHZN+QS3V11EnsVwCiYgOQXMmQNAIgVpFsZ146R+o3l9ltB+KEVKsPW8RCyq2EAw==", + "dev": true + }, "node_modules/@types/geojson": { "version": "7946.0.12", "resolved": "https://registry.npmjs.org/@types/geojson/-/geojson-7946.0.12.tgz", @@ -8443,6 +8451,11 @@ "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz", "integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==" }, + "node_modules/base-64": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/base-64/-/base-64-1.0.0.tgz", + "integrity": "sha512-kwDPIFCGx0NZHog36dj+tHiwP4QMzsZ3AgMViUBKI0+V5n4U0ufTCUMhnQ04diaRI8EX/QcPfql7zlhZ7j4zgg==" + }, "node_modules/base64-js": { "version": "1.5.1", "resolved": "https://registry.npmjs.org/base64-js/-/base64-js-1.5.1.tgz", diff --git a/dev-client/package.json b/dev-client/package.json index 653cad88a..0fd928461 100644 --- a/dev-client/package.json +++ b/dev-client/package.json @@ -20,6 +20,7 @@ "@react-navigation/native": "^6.1.9", "@react-navigation/native-stack": "^6.9.16", "@rnmapbox/maps": "^10.0.15", + "base-64": "^1.0.0", "formik": "^2.4.5", "i18next": "^23.6.0", "native-base": "^3.4.28", @@ -50,6 +51,7 @@ "@babel/runtime": "^7.23.2", "@react-native-community/eslint-config": "^3.2.0", "@tsconfig/react-native": "^3.0.2", + "@types/base-64": "^1.0.1", "@types/jest": "^29.5.6", "@types/react": "^18.2.33", "@types/react-native-vector-icons": "^6.4.16", diff --git a/dev-client/src/prelude.ts b/dev-client/src/prelude.ts new file mode 100644 index 000000000..29b83ba6b --- /dev/null +++ b/dev-client/src/prelude.ts @@ -0,0 +1,17 @@ +// Code in this file that needs to run before anything else +import {decode, encode} from 'base-64'; + +// jwt-decode (used in shared-client) no longer carries a polyfill for browser b64 functions which it uses +// react native JS built-ins does not include these functions, so we need to provide implementation +// see https://github.com/facebook/hermes/issues/1178 for updates +const b64_polyfill = () => { + if (!global.btoa) { + global.btoa = encode; + } + + if (!global.atob) { + global.atob = decode; + } +}; + +b64_polyfill();