Skip to content

Commit cdd34db

Browse files
mnahkiesmikehardy
authored andcommitted
feat: include phoneNumber from PhoneMultiFactorInfo
this is useful for indicating to users which phone number they have enrolled, and distinguishing between factors if there are multiple phone factors enrolled.
1 parent a2e3206 commit cdd34db

File tree

4 files changed

+24
-5
lines changed

4 files changed

+24
-5
lines changed

packages/auth/android/src/main/java/io/invertase/firebase/auth/ReactNativeFirebaseAuthModule.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2553,6 +2553,10 @@ private WritableMap multiFactorInfoToMap(MultiFactorInfo hint) {
25532553
hintMap.putString("factorId", hint.getFactorId());
25542554
hintMap.putString("uid", hint.getUid());
25552555

2556+
if (hint.getFactorId().equals(PhoneMultiFactorGenerator.FACTOR_ID)) {
2557+
hintMap.putString("phoneNumber", ((PhoneMultiFactorInfo) hint).getPhoneNumber());
2558+
}
2559+
25562560
return hintMap;
25572561
}
25582562

packages/auth/e2e/multiFactor.e2e.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -562,6 +562,9 @@ describe('multi-factor modular', function () {
562562
multiFactorResolver.should.be.an.Object();
563563
multiFactorResolver.hints.should.be.an.Array();
564564
multiFactorResolver.hints.length.should.equal(1);
565+
multiFactorResolver.hints[0].factorId.should.equal('phone');
566+
multiFactorResolver.hints[0].phoneNumber.should.equal(phoneNumber);
567+
565568
multiFactorResolver.session.should.be.a.String();
566569

567570
const verificationId = await new firebase.auth.PhoneAuthProvider(

packages/auth/ios/RNFBAuth/RNFBAuthModule.m

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1695,6 +1695,8 @@ - (NSDictionary *)firebaseUserToDict:(FIRUser *)user {
16951695
@"enrollmentTime" : enrollmentTime,
16961696
// @deprecated enrollmentDate kept for backwards compatibility, please use enrollmentTime
16971697
@"enrollmentDate" : enrollmentTime,
1698+
// phoneNumber only present on FIRPhoneMultiFactorInfo
1699+
@"phoneNumber" : hint.phoneNumber == nil ? [NSNull null] : hint.phoneNumber,
16981700
}];
16991701
}
17001702
return enrolledFactors;

packages/auth/lib/index.d.ts

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,21 @@ export namespace FirebaseAuthTypes {
472472
/**
473473
* Contains information about a second factor.
474474
*/
475-
export interface MultiFactorInfo {
475+
export type MultiFactorInfo = PhoneMultiFactorInfo | TotpMultiFactorInfo;
476+
477+
export interface PhoneMultiFactorInfo extends MultiFactorInfoCommon {
478+
factorId: 'phone';
479+
/**
480+
* The phone number used for this factor.
481+
*/
482+
phoneNumber: string;
483+
}
484+
485+
export interface TotpMultiFactorInfo extends MultiFactorInfoCommon {
486+
factorId: 'totp';
487+
}
488+
489+
export interface MultiFactorInfoCommon {
476490
/**
477491
* User friendly name for this factor.
478492
*/
@@ -481,10 +495,6 @@ export namespace FirebaseAuthTypes {
481495
* Time the second factor was enrolled, in UTC.
482496
*/
483497
enrollmentTime: string;
484-
/**
485-
* Type of factor.
486-
*/
487-
factorId: FactorId;
488498
/**
489499
* Unique id for this factor.
490500
*/

0 commit comments

Comments
 (0)