Skip to content

Commit

Permalink
(Feature): Add setLanguageCode method for Firebase Auth
Browse files Browse the repository at this point in the history
  • Loading branch information
david authored and dpa99c committed Sep 30, 2020
1 parent 2b61e90 commit 21bc600
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
* Bug introduced by PR [#482](https://github.com/dpa99c/cordova-plugin-firebasex/pull/482).
* (Android) Add the Firebase Performance Monitoring Gradle plugin to monitor network traffic.
* Resolves [#520](https://github.com/dpa99c/cordova-plugin-firebasex/issues/520).
* (Feature): Add setLanguageCode method for Firebase Auth
* Merged from PR [#527](https://github.com/dpa99c/cordova-plugin-firebasex/pull/527).

# Version 11.0.1
* (iOS) Set the Sign In with Apple capability based on the `IOS_ENABLE_APPLE_SIGNIN` plugin variable.
Expand Down
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ To help ensure this plugin is kept updated, new features are added and bugfixes
- [verifyPhoneNumber](#verifyphonenumber)
- [Android](#android-2)
- [iOS](#ios-2)
- [setLanguageCode](#setLanguageCode)
- [authenticateUserWithEmailAndPassword](#authenticateuserwithemailandpassword)
- [authenticateUserWithGoogle](#authenticateuserwithgoogle)
- [Android](#android-3)
Expand Down Expand Up @@ -2550,6 +2551,17 @@ You can [set up reCAPTCHA verification for iOS](https://firebase.google.com/docs

This adds the `REVERSED_CLIENT_ID` from the `GoogleService-Info.plist` to the list of custom URL schemes in your Xcode project, so you don't need to do this manually.

### setLanguageCode
Sets the user-facing language code for auth operations that can be internationalized, such as sendEmailVerification() or verifyPhoneNumber(). This language code should follow the conventions defined by the IETF in BCP47.

**Parameters**:
- {string} lang - language to change, ex: 'fr' for french

Example usage:

```javascript
FirebasePlugin.setLanguageCode('fr'); // will switch to french
```

### authenticateUserWithEmailAndPassword
Authenticates the user with email/password-based user account to obtain a credential that can be used to sign the user in/link to an existing user account/reauthenticate the user.
Expand Down
23 changes: 23 additions & 0 deletions src/android/FirebasePlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,8 @@ public boolean execute(String action, JSONArray args, CallbackContext callbackCo

} else if (action.equals("verifyPhoneNumber")) {
this.verifyPhoneNumber(callbackContext, args);
} else if (action.equals("setLanguageCode")) {
this.setLanguageCode(callbackContext, args);
} else if (action.equals("authenticateUserWithGoogle")) {
this.authenticateUserWithGoogle(callbackContext, args);
} else if (action.equals("authenticateUserWithApple")) {
Expand Down Expand Up @@ -1456,6 +1458,27 @@ public void onCodeSent(String verificationId, PhoneAuthProvider.ForceResendingTo
});
}

public void setLanguageCode(final CallbackContext callbackContext, final JSONArray args){
cordova.getThreadPool().execute(new Runnable() {
public void run() {
try {
String lang = args.getString(0);

if(lang == null || lang.equals("")){
callbackContext.error("Lang must be specified");
return;
}

FirebaseAuth.getInstance().setLanguageCode(lang);

Log.d(TAG, "Language code setted to "+lang);
} catch (Exception e) {
handleExceptionWithContext(e, callbackContext);
}
}
});
}

public void createUserWithEmailAndPassword(final CallbackContext callbackContext, final JSONArray args){
cordova.getThreadPool().execute(new Runnable() {
public void run() {
Expand Down
1 change: 1 addition & 0 deletions src/ios/FirebasePlugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

// Authentication
- (void)verifyPhoneNumber:(CDVInvokedUrlCommand*)command;
- (void)setLanguageCode:(CDVInvokedUrlCommand*)command;
- (void)createUserWithEmailAndPassword:(CDVInvokedUrlCommand*)command;
- (void)signInUserWithEmailAndPassword:(CDVInvokedUrlCommand*)command;
- (void)authenticateUserWithEmailAndPassword:(CDVInvokedUrlCommand*)command;
Expand Down
10 changes: 10 additions & 0 deletions src/ios/FirebasePlugin.m
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -543,6 +543,16 @@ - (void)verifyPhoneNumber:(CDVInvokedUrlCommand *)command {
}
}

- (void)setLanguageCode:(CDVInvokedUrlCommand *)command {
NSString* lang = [command.arguments objectAtIndex:0];
@try {
[FIRAuth auth].languageCode = lang;
NSLog(@"Language code setted to %@!", lang);
}@catch (NSException *exception) {
[self handlePluginExceptionWithContext:exception :command];
}
}

- (void)createUserWithEmailAndPassword:(CDVInvokedUrlCommand*)command {
@try {
NSString* email = [command.arguments objectAtIndex:0];
Expand Down
5 changes: 5 additions & 0 deletions types/index.d.ts
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,11 @@ interface FirebasePlugin {
timeOutDuration: number,
fakeVerificationCode?: string
): void
setLanguageCode(
lang: string,
success?: () => void,
error?: (err: string) => void
): void
createUserWithEmailAndPassword(
email: string,
password: string,
Expand Down

0 comments on commit 21bc600

Please sign in to comment.