From 984cc2e4740ac58053731e12efa5280e490e9fbc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=BCbner=20Kriszti=C3=A1n?= Date: Wed, 27 Oct 2021 18:20:44 +0200 Subject: [PATCH 1/3] add flag --- jest.setup.ts | 1 + packages/app/lib/internal/FirebaseModule.js | 1 + packages/auth/lib/index.js | 9 ++++++--- packages/firestore/lib/index.js | 7 +++++-- packages/functions/lib/index.js | 9 ++++++--- 5 files changed, 19 insertions(+), 8 deletions(-) diff --git a/jest.setup.ts b/jest.setup.ts index f824111b85..645c77a784 100644 --- a/jest.setup.ts +++ b/jest.setup.ts @@ -28,6 +28,7 @@ jest.doMock('react-native', () => { options: {}, }, ], + FIREBASE_RAW_JSON: '{"asd": "Hello world"}', addListener: jest.fn(), eventsAddListener: jest.fn(), eventsNotifyReady: jest.fn(), diff --git a/packages/app/lib/internal/FirebaseModule.js b/packages/app/lib/internal/FirebaseModule.js index b970643b5c..0a9eaa94bc 100644 --- a/packages/app/lib/internal/FirebaseModule.js +++ b/packages/app/lib/internal/FirebaseModule.js @@ -36,6 +36,7 @@ export default class FirebaseModule { if (firebaseJson) { return firebaseJson; } + console.log(getAppModule().FIREBASE_RAW_JSON); firebaseJson = JSON.parse(getAppModule().FIREBASE_RAW_JSON); return firebaseJson; } diff --git a/packages/auth/lib/index.js b/packages/auth/lib/index.js index 36f1f069e7..48d339a928 100644 --- a/packages/auth/lib/index.js +++ b/packages/auth/lib/index.js @@ -360,19 +360,22 @@ class FirebaseAuthModule extends FirebaseModule { } let _url = url; - if (isAndroid && _url) { + const androidBypassEmulatorUrlRemap = + typeof this.firebaseJson.android_bypass_emulator_url_remap === 'boolean' && + this.firebaseJson.android_bypass_emulator_url_remap; + if (!androidBypassEmulatorUrlRemap && isAndroid && _url) { if (_url.startsWith('http://localhost')) { _url = _url.replace('http://localhost', 'http://10.0.2.2'); // eslint-disable-next-line no-console console.log( - 'Mapping auth host "localhost" to "10.0.2.2" for android emulators. Use real IP on real devices.', + 'Mapping auth host "localhost" to "10.0.2.2" for android emulators. Use real IP on real devices. You can bypass this behaviour with "android_bypass_emulator_url_remap" flag.', ); } if (_url.startsWith('http://127.0.0.1')) { _url = _url.replace('http://127.0.0.1', 'http://10.0.2.2'); // eslint-disable-next-line no-console console.log( - 'Mapping auth host "127.0.0.1" to "10.0.2.2" for android emulators. Use real IP on real devices.', + 'Mapping auth host "127.0.0.1" to "10.0.2.2" for android emulators. Use real IP on real devices. You can bypass this behaviour with "android_bypass_emulator_url_remap" flag.', ); } } diff --git a/packages/firestore/lib/index.js b/packages/firestore/lib/index.js index 6d33bfdc52..aded37bb10 100644 --- a/packages/firestore/lib/index.js +++ b/packages/firestore/lib/index.js @@ -101,12 +101,15 @@ class FirebaseFirestoreModule extends FirebaseModule { throw new Error('firebase.firestore().useEmulator() takes a non-empty host and port'); } let _host = host; - if (isAndroid && _host) { + const androidBypassEmulatorUrlRemap = + typeof this.firebaseJson.android_bypass_emulator_url_remap === 'boolean' && + this.firebaseJson.android_bypass_emulator_url_remap; + if (!androidBypassEmulatorUrlRemap && isAndroid && _host) { if (_host === 'localhost' || _host === '127.0.0.1') { _host = '10.0.2.2'; // eslint-disable-next-line no-console console.log( - 'Mapping firestore host to "10.0.2.2" for android emulators. Use real IP on real devices.', + 'Mapping firestore host to "10.0.2.2" for android emulators. Use real IP on real devices. You can bypass this behaviour with "android_bypass_emulator_url_remap" flag.', ); } } diff --git a/packages/functions/lib/index.js b/packages/functions/lib/index.js index ecd6eb56f4..a27f1b1236 100644 --- a/packages/functions/lib/index.js +++ b/packages/functions/lib/index.js @@ -93,19 +93,22 @@ class FirebaseFunctionsModule extends FirebaseModule { useFunctionsEmulator(origin) { let _origin = origin; - if (isAndroid && _origin) { + const androidBypassEmulatorUrlRemap = + typeof this.firebaseJson.android_bypass_emulator_url_remap === 'boolean' && + this.firebaseJson.android_bypass_emulator_url_remap; + if (!androidBypassEmulatorUrlRemap && isAndroid && _origin) { if (_origin.startsWith('http://localhost')) { _origin = _origin.replace('http://localhost', 'http://10.0.2.2'); // eslint-disable-next-line no-console console.log( - 'Mapping functions host "localhost" to "10.0.2.2" for android emulators. Use real IP on real devices.', + 'Mapping functions host "localhost" to "10.0.2.2" for android emulators. Use real IP on real devices. You can bypass this behaviour with "android_bypass_emulator_url_remap" flag.', ); } if (_origin.startsWith('http://127.0.0.1')) { _origin = _origin.replace('http://127.0.0.1', 'http://10.0.2.2'); // eslint-disable-next-line no-console console.log( - 'Mapping functions host "127.0.0.1" to "10.0.2.2" for android emulators. Use real IP on real devices.', + 'Mapping functions host "127.0.0.1" to "10.0.2.2" for android emulators. Use real IP on real devices. You can bypass this behaviour with "android_bypass_emulator_url_remap" flag.', ); } } From 24b11b9ed16586d8a79e3b23adf8d6e27a00d390 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kriszti=C3=A1n=20H=C3=BCbner?= Date: Mon, 15 Nov 2021 22:17:37 +0100 Subject: [PATCH 2/3] Remove unnecessary log, simplify mock object --- jest.setup.ts | 2 +- packages/app/lib/internal/FirebaseModule.js | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/jest.setup.ts b/jest.setup.ts index 645c77a784..5de4eec690 100644 --- a/jest.setup.ts +++ b/jest.setup.ts @@ -28,7 +28,7 @@ jest.doMock('react-native', () => { options: {}, }, ], - FIREBASE_RAW_JSON: '{"asd": "Hello world"}', + FIREBASE_RAW_JSON: '{}', addListener: jest.fn(), eventsAddListener: jest.fn(), eventsNotifyReady: jest.fn(), diff --git a/packages/app/lib/internal/FirebaseModule.js b/packages/app/lib/internal/FirebaseModule.js index 0a9eaa94bc..b970643b5c 100644 --- a/packages/app/lib/internal/FirebaseModule.js +++ b/packages/app/lib/internal/FirebaseModule.js @@ -36,7 +36,6 @@ export default class FirebaseModule { if (firebaseJson) { return firebaseJson; } - console.log(getAppModule().FIREBASE_RAW_JSON); firebaseJson = JSON.parse(getAppModule().FIREBASE_RAW_JSON); return firebaseJson; } From ca230a362dd8bf1ab56f0b8bb8bc83ea5a4b912b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kriszti=C3=A1n=20H=C3=BCbner?= Date: Mon, 15 Nov 2021 22:17:50 +0100 Subject: [PATCH 3/3] Add flag to documentation --- packages/app/firebase-schema.json | 4 ++++ tests/firebase.json | 1 + 2 files changed, 5 insertions(+) diff --git a/packages/app/firebase-schema.json b/packages/app/firebase-schema.json index 660549c005..67de22715b 100644 --- a/packages/app/firebase-schema.json +++ b/packages/app/firebase-schema.json @@ -105,6 +105,10 @@ "android_background_activity_names": { "description": "The names (as returned by `getShortClassName()` of Activities used outside the context of react native.\nThese are ignored when determining if the app is in foreground for purposes of calling javascript background handlers", "type": "array" + }, + "android_bypass_emulator_url_remap": { + "description": "On android devices, the urls of firebase emulators will be remapped from localhost to 10.0.2.2. If you don't need this behaviour set this fleg to `true`.", + "type": "boolean" } } } diff --git a/tests/firebase.json b/tests/firebase.json index f7d552dc6f..cff550b974 100644 --- a/tests/firebase.json +++ b/tests/firebase.json @@ -34,6 +34,7 @@ "android_task_executor_maximum_pool_size": 10, "android_task_executor_keep_alive_seconds": 3, + "android_bypass_emulator_url_remap": false, "rnfirebase_json_testing_string": "abc", "rnfirebase_json_testing_boolean_false": false,