Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Polyfill browser b64 functions to fix login #567

Merged
merged 1 commit into from
Nov 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dev-client/index.js
Original file line number Diff line number Diff line change
@@ -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
Expand Down
13 changes: 13 additions & 0 deletions dev-client/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions dev-client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
17 changes: 17 additions & 0 deletions dev-client/src/prelude.ts
Original file line number Diff line number Diff line change
@@ -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();