Skip to content
This repository was archived by the owner on Apr 4, 2023. It is now read-only.

Commit b8b9d7c

Browse files
#376 Add support for firebase phone authentication (support all Android flows)
1 parent 6d1c06d commit b8b9d7c

File tree

7 files changed

+19
-20
lines changed

7 files changed

+19
-20
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
[Firebase Android SDK Changelog](https://firebase.google.com/support/release-notes/android)
55

66

7-
## 4.0.0 & 4.0.1 (2017, June 20)
7+
## 4.0.0, 4.0.1, 4.0.2 (2017, June 20)
88

99
[Full changelog](https://github.com/EddyVerbruggen/nativescript-plugin-firebase/milestone/26?closed=1)
1010

docs/AUTHENTICATION.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,8 @@ Don't forget to enable email-password login in your firebase instance.
239239
firebase.login({
240240
type: firebase.LoginType.PHONE,
241241
phoneOptions: {
242-
phoneNumber: '+12345678900'
242+
phoneNumber: '+12345678900',
243+
verificationPrompt: "The received verification code" // default "Verification code"
243244
}
244245
}).then(
245246
function (result) {

firebase-common.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,8 @@ firebase.strongTypeify = function (value) {
120120
return value;
121121
};
122122

123-
firebase.requestPhoneAuthVerificationCode = function (onUserResponse) {
124-
dialogs.prompt("Verification code").then(function (promptResult) {
123+
firebase.requestPhoneAuthVerificationCode = function (onUserResponse, verificationPrompt) {
124+
dialogs.prompt(verificationPrompt || "Verification code").then(function (promptResult) {
125125
if (!promptResult.result) {
126126
return;
127127
}

firebase.android.js

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -916,12 +916,13 @@ firebase.login = function (arg) {
916916

917917
var OnVerificationStateChangedCallbacks = com.google.firebase.auth.PhoneAuthProvider.OnVerificationStateChangedCallbacks.extend({
918918
onVerificationCompleted: function(phoneAuthCredential) {
919+
console.log("phone number verification completed");
919920
firebase._verifyPhoneNumberInProgress = false;
920921
// the user previously authenticated with phone (or no prompt was required), so sign in and complete
921922
firebaseAuth.signInWithCredential(phoneAuthCredential).addOnCompleteListener(onCompleteListener);
922923
},
923924
onVerificationFailed: function(firebaseException) {
924-
console.log("onVerificationStateChangedCallbacks.onVerificationFailed: " + firebaseException)
925+
console.log("onVerificationStateChangedCallbacks.onVerificationFailed: " + firebaseException);
925926
firebase._verifyPhoneNumberInProgress = false;
926927
var errorMessage = firebaseException.getMessage();
927928
if (errorMessage.indexOf("INVALID_APP_CREDENTIAL") > -1) {
@@ -931,21 +932,14 @@ firebase.login = function (arg) {
931932
}
932933
},
933934
onCodeSent: function(verificationId, forceResendingToken) {
934-
// TODO these are printed, but need to run on a device with a mathing phonenr of course..
935-
console.log("onVerificationStateChangedCallbacks.onCodeSent.verificationId: " + verificationId)
936-
console.log("onVerificationStateChangedCallbacks.onCodeSent.forceResendingToken: " + forceResendingToken)
937-
938-
// in some cases the prompt is not required, and onVerificationCompleted is called immediately.. not sure about the timing, so using a short timeout
935+
// If the device has a SIM card auto-verification may occur in the background (eventually calling onVerificationCompleted)
936+
// .. so the prompt would be redundant, but it's recommended by Google not to wait to long before showing the prompt
939937
setTimeout(function() {
940938
if (firebase._verifyPhoneNumberInProgress) {
941939
firebase._verifyPhoneNumberInProgress = false;
942-
943940
firebase.requestPhoneAuthVerificationCode(function(userResponse) {
944-
console.log("onVerificationStateChangedCallbacks com.google.firebase.auth.PhoneAuthCredential: " + com.google.firebase.auth.PhoneAuthCredential)
945-
var authCredential = com.google.firebase.auth.PhoneAuthCredential.getCredential(verificationId, userResponse);
946-
console.log("onVerificationStateChangedCallbacks authCredential: " + authCredential)
941+
var authCredential = com.google.firebase.auth.PhoneAuthProvider.getCredential(verificationId, userResponse);
947942
var user = com.google.firebase.auth.FirebaseAuth.getInstance().getCurrentUser();
948-
console.log("onVerificationStateChangedCallbacks user: " + user)
949943
if (user) {
950944
if (firebase._alreadyLinkedToAuthProvider(user, "phone")) {
951945
firebaseAuth.signInWithCredential(authCredential).addOnCompleteListener(onCompleteListener);
@@ -955,9 +949,9 @@ firebase.login = function (arg) {
955949
} else {
956950
firebaseAuth.signInWithCredential(authCredential).addOnCompleteListener(onCompleteListener);
957951
}
958-
});
952+
}, arg.phoneOptions.verificationPrompt);
959953
}
960-
}, 1000);
954+
}, 3000);
961955
}
962956
});
963957

firebase.d.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,11 @@ export interface FirebasePasswordLoginOptions {
174174

175175
export interface FirebasePhoneLoginOptions {
176176
phoneNumber: string;
177-
// verificationCodePrompt?: string;
177+
/**
178+
* The message show to the user that prompts him to enter the received verification code.
179+
* Default: "Verification code".
180+
*/
181+
verificationPrompt?: string;
178182
}
179183

180184
export interface FirebaseGoogleLoginOptions {

firebase.ios.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1067,7 +1067,7 @@ firebase.login = function (arg) {
10671067
} else {
10681068
fAuth.signInWithCredentialCompletion(fIRAuthCredential, onCompletion);
10691069
}
1070-
});
1070+
}, arg.phoneOptions.verificationPrompt);
10711071
});
10721072

10731073
} else if (arg.type === firebase.LoginType.CUSTOM) {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "nativescript-plugin-firebase",
3-
"version": "4.0.1",
3+
"version": "4.0.2",
44
"description": "Fire. Base. Firebase!",
55
"main": "firebase",
66
"typings": "index.d.ts",

0 commit comments

Comments
 (0)