From 8511705d8ee4b3795acb9c03720998d3afc80418 Mon Sep 17 00:00:00 2001 From: Elliot Hesp Date: Thu, 30 Nov 2017 10:02:01 +0000 Subject: [PATCH 01/15] [auth][android] Add methods to set the auth language via code or device language --- .../firebase/auth/RNFirebaseAuth.java | 26 +++++++++++++++++++ lib/modules/auth/index.js | 17 ++++++++++++ 2 files changed, 43 insertions(+) diff --git a/android/src/main/java/io/invertase/firebase/auth/RNFirebaseAuth.java b/android/src/main/java/io/invertase/firebase/auth/RNFirebaseAuth.java index 601f5cb58a..366490887d 100644 --- a/android/src/main/java/io/invertase/firebase/auth/RNFirebaseAuth.java +++ b/android/src/main/java/io/invertase/firebase/auth/RNFirebaseAuth.java @@ -1129,6 +1129,7 @@ public void onComplete(@NonNull Task task) { /** * fetchProvidersForEmail * + * @param appName * @param promise */ @ReactMethod @@ -1163,6 +1164,31 @@ public void onComplete(@NonNull Task task) { }); } + /** + * Set the language code for the auth module + * @param appName + * @param code + */ + @ReactMethod + public void setLanguageCode(String appName, String code) { + FirebaseApp firebaseApp = FirebaseApp.getInstance(appName); + FirebaseAuth firebaseAuth = FirebaseAuth.getInstance(firebaseApp); + + firebaseAuth.setLanguageCode(code); + } + + /** + * Use the device language + * @param appName + */ + @ReactMethod + public void useDeviceLanguage(String appName) { + FirebaseApp firebaseApp = FirebaseApp.getInstance(appName); + FirebaseAuth firebaseAuth = FirebaseAuth.getInstance(firebaseApp); + + firebaseAuth.useAppLanguage(); + } + /* ------------------ * INTERNAL HELPERS * ---------------- */ diff --git a/lib/modules/auth/index.js b/lib/modules/auth/index.js index 67abfe8a46..accc5f8efc 100644 --- a/lib/modules/auth/index.js +++ b/lib/modules/auth/index.js @@ -322,6 +322,23 @@ export default class Auth extends ModuleBase { return this._native.fetchProvidersForEmail(email); } + /** + * Sets the language for the auth module using the device language + * @returns {*} + */ + useDeviceLanguage() { + return this._native.useDeviceLanguage(); + } + + /** + * Sets the language for the auth module + * @param code + * @returns {*} + */ + set languageCode(code) { + return this._native.setLanguageCode(code); + } + /** * Get the currently signed in user * @return {Promise} From b266a0451042bf63a638a4b25df385ebc9fffec6 Mon Sep 17 00:00:00 2001 From: Elliot Hesp Date: Thu, 30 Nov 2017 10:17:04 +0000 Subject: [PATCH 02/15] [auth][ios] Add auth language methods --- ios/RNFirebase/auth/RNFirebaseAuth.m | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/ios/RNFirebase/auth/RNFirebaseAuth.m b/ios/RNFirebase/auth/RNFirebaseAuth.m index 37662dcbce..7668fd0f44 100644 --- a/ios/RNFirebase/auth/RNFirebaseAuth.m +++ b/ios/RNFirebase/auth/RNFirebaseAuth.m @@ -912,6 +912,34 @@ - (FIRAuthCredential *)getCredentialForProvider:(NSString *)provider token:(NSSt return credential; } +/** + setLanguageCode + + @param NSString code + @return + */ +RCT_EXPORT_METHOD(setLanguageCode: + (NSString *) appName + code: + (NSString *) code) { + FIRApp *firApp = [FIRApp appNamed:appName]; + + [FIRAuth authWithApp:firApp].languageCode = code; +} + +/** + useDeviceLanguage + + @param NSString code + @return + */ +RCT_EXPORT_METHOD(useDeviceLanguage: + (NSString *) appName) { + FIRApp *firApp = [FIRApp appNamed:appName]; + + [[FIRAuth authWithApp:firApp] useAppLanguage]; +} + // This is here to protect against bugs in the iOS SDK which don't // correctly refresh the user object when performing certain operations - (void)reloadAndReturnUser:(FIRUser *)user From fb8c08c7f6034ad8569a3c4eceb53d4cf519a281 Mon Sep 17 00:00:00 2001 From: Elliot Hesp Date: Thu, 30 Nov 2017 10:56:01 +0000 Subject: [PATCH 03/15] [auth] Remove unnecessary return --- lib/modules/auth/index.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/modules/auth/index.js b/lib/modules/auth/index.js index accc5f8efc..bf32aa262c 100644 --- a/lib/modules/auth/index.js +++ b/lib/modules/auth/index.js @@ -327,7 +327,7 @@ export default class Auth extends ModuleBase { * @returns {*} */ useDeviceLanguage() { - return this._native.useDeviceLanguage(); + this._native.useDeviceLanguage(); } /** @@ -335,8 +335,8 @@ export default class Auth extends ModuleBase { * @param code * @returns {*} */ - set languageCode(code) { - return this._native.setLanguageCode(code); + set languageCode(code: string) { + this._native.setLanguageCode(code); } /** From e452f514a324c63522fffdf08c818a29b5c409b9 Mon Sep 17 00:00:00 2001 From: Elliot Hesp Date: Thu, 30 Nov 2017 11:27:59 +0000 Subject: [PATCH 04/15] [utils] Allow _native to return statics --- lib/utils/index.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/utils/index.js b/lib/utils/index.js index 6f619e4e62..4c1697d81c 100644 --- a/lib/utils/index.js +++ b/lib/utils/index.js @@ -351,9 +351,13 @@ export function nativeWithApp(appName: string, NativeModule: Object) { for (let i = 0, len = methods.length; i < len; i++) { const method = methods[i]; - native[method] = (...args) => { - return NativeModule[method](...[appName, ...args]); - }; + if (isFunction(NativeModule[method])) { + native[method] = (...args) => { + return NativeModule[method](...[appName, ...args]); + }; + } else { + native[method] = NativeModule[method]; + } } return native; From 0083ef7a66be8b141ee1f0866376d200d3a2659a Mon Sep 17 00:00:00 2001 From: Elliot Hesp Date: Thu, 30 Nov 2017 11:41:40 +0000 Subject: [PATCH 05/15] [auth][android] Add languageCode getter --- .../firebase/auth/RNFirebaseAuth.java | 26 +++++++++++++++++++ lib/modules/auth/index.js | 6 +++++ 2 files changed, 32 insertions(+) diff --git a/android/src/main/java/io/invertase/firebase/auth/RNFirebaseAuth.java b/android/src/main/java/io/invertase/firebase/auth/RNFirebaseAuth.java index 366490887d..2a8f88ed3c 100644 --- a/android/src/main/java/io/invertase/firebase/auth/RNFirebaseAuth.java +++ b/android/src/main/java/io/invertase/firebase/auth/RNFirebaseAuth.java @@ -6,6 +6,7 @@ import android.net.Uri; import android.support.annotation.NonNull; +import java.util.Map; import java.util.concurrent.TimeUnit; import java.util.HashMap; import java.util.List; @@ -1439,4 +1440,29 @@ private void sendPhoneStateEvent(String appName, String requestKey, String type, eventMap.putMap("state", state); Utils.sendEvent(mReactContext, "phone_auth_state_changed", eventMap); } + + /** + * Constants bootstrapped on react native app boot + * + * @return + */ + @Override + public Map getConstants() { + Map constants = new HashMap<>(); + + List firebaseAppList = FirebaseApp.getApps(getReactApplicationContext()); + final Map appLanguage = new HashMap<>(); + + for (FirebaseApp app : firebaseAppList) { + String appName = app.getName(); + + FirebaseApp instance = FirebaseApp.getInstance(appName); + FirebaseAuth firebaseAuth = FirebaseAuth.getInstance(instance); + + appLanguage.put(appName, firebaseAuth.getLanguageCode()); + } + + constants.put("APP_LANGUAGE", appLanguage); + return constants; + } } diff --git a/lib/modules/auth/index.js b/lib/modules/auth/index.js index bf32aa262c..e154fc284a 100644 --- a/lib/modules/auth/index.js +++ b/lib/modules/auth/index.js @@ -36,6 +36,7 @@ export default class Auth extends ModuleBase { super(firebaseApp, options, true); this._user = null; this._authResult = null; + this._languageCode = this._native.APP_LANGUAGE[firebaseApp._name] || null; this.addListener( // sub to internal native event - this fans out to @@ -336,6 +337,7 @@ export default class Auth extends ModuleBase { * @returns {*} */ set languageCode(code: string) { + this._languageCode = code; this._native.setLanguageCode(code); } @@ -351,6 +353,10 @@ export default class Auth extends ModuleBase { return 'firebase:auth'; } + get languageCode(): string { + return this._languageCode; + } + /** * KNOWN UNSUPPORTED METHODS */ From c736a6bb5144626eee4a20151900d9da9525ae97 Mon Sep 17 00:00:00 2001 From: Elliot Hesp Date: Thu, 30 Nov 2017 12:08:12 +0000 Subject: [PATCH 06/15] [auth][ios] Add app language constants --- ios/RNFirebase/auth/RNFirebaseAuth.m | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/ios/RNFirebase/auth/RNFirebaseAuth.m b/ios/RNFirebase/auth/RNFirebaseAuth.m index 7668fd0f44..de68bed220 100644 --- a/ios/RNFirebase/auth/RNFirebaseAuth.m +++ b/ios/RNFirebase/auth/RNFirebaseAuth.m @@ -1166,6 +1166,25 @@ - (void)promiseWithUser:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseReje return output; } +/** + * React native constant exports - exports native firebase apps mainly + * @return NSDictionary + */ +- (NSDictionary *)constantsToExport { + NSMutableDictionary *constants = [NSMutableDictionary new]; + NSDictionary *firApps = [FIRApp allApps]; + NSMutableDictionary *appLanguage = [NSMutableDictionary new]; + + for (id key in firApps) { + FIRApp *firApp = firApps[key]; + + appLanguage[firApp.name] = [FIRAuth authWithApp:firApp].languageCode; + } + + constants[@"APP_LANGUAGE"] = appLanguage; + return constants; +} + /** Converts a FIRUser instance into a dictionary to send via RNBridge From 7cfcb4efa0b2aa7b14b46ab6f4a3942c4db7e808 Mon Sep 17 00:00:00 2001 From: Elliot Hesp Date: Thu, 30 Nov 2017 12:56:28 +0000 Subject: [PATCH 07/15] [auth] Update typescript --- lib/index.d.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/lib/index.d.ts b/lib/index.d.ts index 688dd9bc0e..c960dd8819 100644 --- a/lib/index.d.ts +++ b/lib/index.d.ts @@ -637,6 +637,11 @@ declare module "react-native-firebase" { */ currentUser: User | null + /** + * Gets/Sets the language for the app instance + */ + languageCode: string | null; + /** * Listen for changes in the users auth state (logging in and out). * This method returns a unsubscribe function to stop listening to events. @@ -705,6 +710,11 @@ declare module "react-native-firebase" { */ signOut(): Promise + /** + * Sets the language for the auth instance to the device language + */ + useDeviceLanguage(): void + [key: string]: any; } } From f970d882ba5afec847056e8aebdd6f97b8f1f19f Mon Sep 17 00:00:00 2001 From: Elliot Hesp Date: Sat, 6 Jan 2018 14:48:07 +0000 Subject: [PATCH 08/15] Ignore atlassian-ide-plugin --- .gitignore | 1 + atlassian-ide-plugin.xml | 5 ----- 2 files changed, 1 insertion(+), 5 deletions(-) delete mode 100644 atlassian-ide-plugin.xml diff --git a/.gitignore b/.gitignore index 7a86822623..3590e23d85 100644 --- a/.gitignore +++ b/.gitignore @@ -9,6 +9,7 @@ npm-debug.log *.perspectivev3 *.xcuserstate project.xcworkspace/ +atlassian-ide-plugin xcuserdata/ # Example diff --git a/atlassian-ide-plugin.xml b/atlassian-ide-plugin.xml deleted file mode 100644 index b68e35d1bb..0000000000 --- a/atlassian-ide-plugin.xml +++ /dev/null @@ -1,5 +0,0 @@ - - - - - \ No newline at end of file From 9ea0a5cc7fbcbf4bd6d672b1bc0c80fdb69b7ab6 Mon Sep 17 00:00:00 2001 From: Elliot Hesp Date: Sat, 6 Jan 2018 15:14:11 +0000 Subject: [PATCH 09/15] [auth] Move useDeviceLanguage to unsupported method --- lib/index.d.ts | 5 ----- lib/modules/auth/index.js | 16 ++++++---------- 2 files changed, 6 insertions(+), 15 deletions(-) diff --git a/lib/index.d.ts b/lib/index.d.ts index 2b4b17bcc8..f5e42abf4e 100644 --- a/lib/index.d.ts +++ b/lib/index.d.ts @@ -714,11 +714,6 @@ declare module "react-native-firebase" { */ signOut(): Promise - /** - * Sets the language for the auth instance to the device language - */ - useDeviceLanguage(): void - [key: string]: any; } } diff --git a/lib/modules/auth/index.js b/lib/modules/auth/index.js index 1ea2c31293..23524d75d1 100644 --- a/lib/modules/auth/index.js +++ b/lib/modules/auth/index.js @@ -48,7 +48,7 @@ export default class Auth extends ModuleBase { }); this._user = null; this._authResult = null; - this._languageCode = this._native.APP_LANGUAGE[firebaseApp._name] || null; + this._languageCode = getNativeModule(this).APP_LANGUAGE[app._name] || null; SharedEventEmitter.addListener( // sub to internal native event - this fans out to @@ -335,14 +335,6 @@ export default class Auth extends ModuleBase { return getNativeModule(this).fetchProvidersForEmail(email); } - /** - * Sets the language for the auth module using the device language - * @returns {*} - */ - useDeviceLanguage() { - this._native.useDeviceLanguage(); - } - /** * Sets the language for the auth module * @param code @@ -350,7 +342,7 @@ export default class Auth extends ModuleBase { */ set languageCode(code: string) { this._languageCode = code; - this._native.setLanguageCode(code); + getNativeModule(this).setLanguageCode(code); } /** @@ -392,6 +384,10 @@ export default class Auth extends ModuleBase { signInWithRedirect() { throw new Error(INTERNALS.STRINGS.ERROR_UNSUPPORTED_MODULE_METHOD('auth', 'signInWithRedirect')); } + + useDeviceLanguage() { + throw new Error(INTERNALS.STRINGS.ERROR_UNSUPPORTED_MODULE_METHOD('auth', 'useDeviceLanguage')); + } } export const statics = { From a8896bc9b883f77b96e18edcf1f7a117f7dd45ac Mon Sep 17 00:00:00 2001 From: Elliot Hesp Date: Sat, 6 Jan 2018 15:14:49 +0000 Subject: [PATCH 10/15] [auth] Add language code tests --- tests/src/tests/auth/authTests.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tests/src/tests/auth/authTests.js b/tests/src/tests/auth/authTests.js index ad838968a6..31d70d72d6 100644 --- a/tests/src/tests/auth/authTests.js +++ b/tests/src/tests/auth/authTests.js @@ -356,6 +356,18 @@ function authTests({ tryCatch, describe, it, firebase }) { return firebase.native.auth().signOut().then(successCb).catch(failureCb); }); }); + + it('it should change the language code', () => { + firebase.native.auth().languageCode = 'en'; + if (firebase.native.auth().languageCode !== 'en') { + throw new Error('Expected language code to be "en".'); + } + firebase.native.auth().languageCode = 'fr'; + if (firebase.native.auth().languageCode !== 'en') { + throw new Error('Expected language code to be "fr".'); + } + firebase.native.auth().languageCode = 'en'; + }); }); } From f4d29b9136882ce26eb49333abd04f88d06940f2 Mon Sep 17 00:00:00 2001 From: Elliot Hesp Date: Sat, 6 Jan 2018 15:17:59 +0000 Subject: [PATCH 11/15] [auth] Fix incorrect languageCode test --- tests/src/tests/auth/authTests.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/src/tests/auth/authTests.js b/tests/src/tests/auth/authTests.js index 31d70d72d6..5848db2611 100644 --- a/tests/src/tests/auth/authTests.js +++ b/tests/src/tests/auth/authTests.js @@ -363,7 +363,7 @@ function authTests({ tryCatch, describe, it, firebase }) { throw new Error('Expected language code to be "en".'); } firebase.native.auth().languageCode = 'fr'; - if (firebase.native.auth().languageCode !== 'en') { + if (firebase.native.auth().languageCode !== 'fr') { throw new Error('Expected language code to be "fr".'); } firebase.native.auth().languageCode = 'en'; From 409cd70ab1d418ac9f91c12ba6620f399a31ce06 Mon Sep 17 00:00:00 2001 From: Elliot Hesp Date: Mon, 8 Jan 2018 10:07:15 +0000 Subject: [PATCH 12/15] [auth] Update iOS methods to internals change --- ios/RNFirebase/auth/RNFirebaseAuth.m | 8 ++++---- lib/modules/auth/index.js | 1 + 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/ios/RNFirebase/auth/RNFirebaseAuth.m b/ios/RNFirebase/auth/RNFirebaseAuth.m index 4ad5b5268a..607c9070d5 100644 --- a/ios/RNFirebase/auth/RNFirebaseAuth.m +++ b/ios/RNFirebase/auth/RNFirebaseAuth.m @@ -928,10 +928,10 @@ - (FIRAuthCredential *)getCredentialForProvider:(NSString *)provider token:(NSSt @return */ RCT_EXPORT_METHOD(setLanguageCode: - (NSString *) appName + (NSString *) appDisplayName code: (NSString *) code) { - FIRApp *firApp = [FIRApp appNamed:appName]; + FIRApp *firApp = [RNFirebaseUtil getApp:appDisplayName]; [FIRAuth authWithApp:firApp].languageCode = code; } @@ -943,8 +943,8 @@ - (FIRAuthCredential *)getCredentialForProvider:(NSString *)provider token:(NSSt @return */ RCT_EXPORT_METHOD(useDeviceLanguage: - (NSString *) appName) { - FIRApp *firApp = [FIRApp appNamed:appName]; + (NSString *) appDisplayName) { + FIRApp *firApp = [RNFirebaseUtil getApp:appDisplayName]; [[FIRAuth authWithApp:firApp] useAppLanguage]; } diff --git a/lib/modules/auth/index.js b/lib/modules/auth/index.js index 23524d75d1..de5ffbdab1 100644 --- a/lib/modules/auth/index.js +++ b/lib/modules/auth/index.js @@ -385,6 +385,7 @@ export default class Auth extends ModuleBase { throw new Error(INTERNALS.STRINGS.ERROR_UNSUPPORTED_MODULE_METHOD('auth', 'signInWithRedirect')); } + // firebase issue - https://github.com/invertase/react-native-firebase/pull/655#issuecomment-349904680 useDeviceLanguage() { throw new Error(INTERNALS.STRINGS.ERROR_UNSUPPORTED_MODULE_METHOD('auth', 'useDeviceLanguage')); } From 06424aff14634e4c59d719a4a23b84500408af2a Mon Sep 17 00:00:00 2001 From: Elliot Hesp Date: Mon, 8 Jan 2018 11:30:59 +0000 Subject: [PATCH 13/15] [auth] use [DEFAULT] languageCode for dynamic apps --- lib/modules/auth/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/modules/auth/index.js b/lib/modules/auth/index.js index de5ffbdab1..eb20e2378a 100644 --- a/lib/modules/auth/index.js +++ b/lib/modules/auth/index.js @@ -48,7 +48,7 @@ export default class Auth extends ModuleBase { }); this._user = null; this._authResult = null; - this._languageCode = getNativeModule(this).APP_LANGUAGE[app._name] || null; + this._languageCode = getNativeModule(this).APP_LANGUAGE[app._name] || getNativeModule(this).APP_LANGUAGE['[DEFAULT]']; SharedEventEmitter.addListener( // sub to internal native event - this fans out to From f320d9243ae43b0e0a1ce0f349fd42412aa8a859 Mon Sep 17 00:00:00 2001 From: Michael Diarmid Date: Wed, 17 Jan 2018 15:21:21 +0000 Subject: [PATCH 14/15] Update index.js --- lib/utils/index.js | 24 ------------------------ 1 file changed, 24 deletions(-) diff --git a/lib/utils/index.js b/lib/utils/index.js index 09e3d65702..994bab1dac 100644 --- a/lib/utils/index.js +++ b/lib/utils/index.js @@ -340,30 +340,6 @@ export function nativeToJSError(code: string, message: string, additionalProps?: return error; } -/** - * TODO is this needed? - * Prepends appName arg to all native method calls - * @param appName - * @param NativeModule - */ -export function nativeWithApp(appName: string, NativeModule: Object) { - const native = {}; - const methods = Object.keys(NativeModule); - - for (let i = 0, len = methods.length; i < len; i++) { - const method = methods[i]; - if (isFunction(NativeModule[method])) { - native[method] = (...args) => { - return NativeModule[method](...[appName, ...args]); - }; - } else { - native[method] = NativeModule[method]; - } - } - - return native; -} - /** * * @param object From 983d273846660c2cbd27481eb4cc61ca6720bc8e Mon Sep 17 00:00:00 2001 From: Michael Diarmid Date: Wed, 17 Jan 2018 15:22:39 +0000 Subject: [PATCH 15/15] Update index.js --- lib/modules/auth/index.js | 4 ---- 1 file changed, 4 deletions(-) diff --git a/lib/modules/auth/index.js b/lib/modules/auth/index.js index eb20e2378a..e5615821e9 100644 --- a/lib/modules/auth/index.js +++ b/lib/modules/auth/index.js @@ -353,10 +353,6 @@ export default class Auth extends ModuleBase { return this._user; } - get namespace(): string { - return 'firebase:auth'; - } - get languageCode(): string { return this._languageCode; }