Skip to content

Commit 88bded1

Browse files
authored
fix(auth, iOS): fix an error where MultifactorInfo factorId could be null on iOS (#9367)
1 parent 89c4c42 commit 88bded1

File tree

8 files changed

+38
-21
lines changed

8 files changed

+38
-21
lines changed

packages/firebase_auth/firebase_auth/android/src/main/java/io/flutter/plugins/firebase/auth/GeneratedAndroidFirebaseAuth.java

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -166,16 +166,13 @@ public void setEnrollmentTimestamp(@NonNull Double setterArg) {
166166
this.enrollmentTimestamp = setterArg;
167167
}
168168

169-
private @NonNull String factorId;
169+
private @Nullable String factorId;
170170

171-
public @NonNull String getFactorId() {
171+
public @Nullable String getFactorId() {
172172
return factorId;
173173
}
174174

175-
public void setFactorId(@NonNull String setterArg) {
176-
if (setterArg == null) {
177-
throw new IllegalStateException("Nonnull field \"factorId\" is null.");
178-
}
175+
public void setFactorId(@Nullable String setterArg) {
179176
this.factorId = setterArg;
180177
}
181178

@@ -222,7 +219,7 @@ public static final class Builder {
222219

223220
private @Nullable String factorId;
224221

225-
public @NonNull Builder setFactorId(@NonNull String setterArg) {
222+
public @NonNull Builder setFactorId(@Nullable String setterArg) {
226223
this.factorId = setterArg;
227224
return this;
228225
}

packages/firebase_auth/firebase_auth/example/ios/Runner.xcodeproj/project.pbxproj

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,7 @@
275275
"${BUILT_PRODUCTS_DIR}/FirebaseAuth/FirebaseAuth.framework",
276276
"${BUILT_PRODUCTS_DIR}/FirebaseCore/FirebaseCore.framework",
277277
"${BUILT_PRODUCTS_DIR}/FirebaseCoreDiagnostics/FirebaseCoreDiagnostics.framework",
278+
"${BUILT_PRODUCTS_DIR}/FirebaseCoreInternal/FirebaseCoreInternal.framework",
278279
"${BUILT_PRODUCTS_DIR}/GTMAppAuth/GTMAppAuth.framework",
279280
"${BUILT_PRODUCTS_DIR}/GTMSessionFetcher/GTMSessionFetcher.framework",
280281
"${BUILT_PRODUCTS_DIR}/GoogleDataTransport/GoogleDataTransport.framework",
@@ -292,6 +293,7 @@
292293
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/FirebaseAuth.framework",
293294
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/FirebaseCore.framework",
294295
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/FirebaseCoreDiagnostics.framework",
296+
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/FirebaseCoreInternal.framework",
295297
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/GTMAppAuth.framework",
296298
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/GTMSessionFetcher.framework",
297299
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/GoogleDataTransport.framework",
@@ -409,7 +411,10 @@
409411
"$(PROJECT_DIR)/Flutter",
410412
);
411413
INFOPLIST_FILE = Runner/Info.plist;
412-
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
414+
LD_RUNPATH_SEARCH_PATHS = (
415+
"$(inherited)",
416+
"@executable_path/Frameworks",
417+
);
413418
LIBRARY_SEARCH_PATHS = (
414419
"$(inherited)",
415420
"$(PROJECT_DIR)/Flutter",
@@ -542,7 +547,10 @@
542547
"$(PROJECT_DIR)/Flutter",
543548
);
544549
INFOPLIST_FILE = Runner/Info.plist;
545-
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
550+
LD_RUNPATH_SEARCH_PATHS = (
551+
"$(inherited)",
552+
"@executable_path/Frameworks",
553+
);
546554
LIBRARY_SEARCH_PATHS = (
547555
"$(inherited)",
548556
"$(PROJECT_DIR)/Flutter",
@@ -570,7 +578,10 @@
570578
"$(PROJECT_DIR)/Flutter",
571579
);
572580
INFOPLIST_FILE = Runner/Info.plist;
573-
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
581+
LD_RUNPATH_SEARCH_PATHS = (
582+
"$(inherited)",
583+
"@executable_path/Frameworks",
584+
);
574585
LIBRARY_SEARCH_PATHS = (
575586
"$(inherited)",
576587
"$(PROJECT_DIR)/Flutter",

packages/firebase_auth/firebase_auth/example/lib/profile.dart

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,14 @@ class _ProfilePageState extends State<ProfilePage> {
176176
child: const Text('Verify Email'),
177177
),
178178
const SizedBox(height: 20),
179+
TextButton(
180+
onPressed: () async {
181+
final a = await user.multiFactor.getEnrolledFactors();
182+
print(a);
183+
},
184+
child: const Text('Get enrolled factors'),
185+
),
186+
const SizedBox(height: 20),
179187
TextFormField(
180188
controller: phoneController,
181189
decoration: const InputDecoration(

packages/firebase_auth/firebase_auth/ios/Classes/messages.g.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,12 @@ NS_ASSUME_NONNULL_BEGIN
3333
- (instancetype)init NS_UNAVAILABLE;
3434
+ (instancetype)makeWithDisplayName:(nullable NSString *)displayName
3535
enrollmentTimestamp:(NSNumber *)enrollmentTimestamp
36-
factorId:(NSString *)factorId
36+
factorId:(nullable NSString *)factorId
3737
uid:(NSString *)uid
3838
phoneNumber:(nullable NSString *)phoneNumber;
3939
@property(nonatomic, copy, nullable) NSString *displayName;
4040
@property(nonatomic, strong) NSNumber *enrollmentTimestamp;
41-
@property(nonatomic, copy) NSString *factorId;
41+
@property(nonatomic, copy, nullable) NSString *factorId;
4242
@property(nonatomic, copy) NSString *uid;
4343
@property(nonatomic, copy, nullable) NSString *phoneNumber;
4444
@end

packages/firebase_auth/firebase_auth/ios/Classes/messages.g.m

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ - (NSDictionary *)toMap {
102102
@implementation PigeonMultiFactorInfo
103103
+ (instancetype)makeWithDisplayName:(nullable NSString *)displayName
104104
enrollmentTimestamp:(NSNumber *)enrollmentTimestamp
105-
factorId:(NSString *)factorId
105+
factorId:(nullable NSString *)factorId
106106
uid:(NSString *)uid
107107
phoneNumber:(nullable NSString *)phoneNumber {
108108
PigeonMultiFactorInfo *pigeonResult = [[PigeonMultiFactorInfo alloc] init];
@@ -119,7 +119,6 @@ + (PigeonMultiFactorInfo *)fromMap:(NSDictionary *)dict {
119119
pigeonResult.enrollmentTimestamp = GetNullableObject(dict, @"enrollmentTimestamp");
120120
NSAssert(pigeonResult.enrollmentTimestamp != nil, @"");
121121
pigeonResult.factorId = GetNullableObject(dict, @"factorId");
122-
NSAssert(pigeonResult.factorId != nil, @"");
123122
pigeonResult.uid = GetNullableObject(dict, @"uid");
124123
NSAssert(pigeonResult.uid != nil, @"");
125124
pigeonResult.phoneNumber = GetNullableObject(dict, @"phoneNumber");

packages/firebase_auth/firebase_auth_platform_interface/lib/src/method_channel/utils/pigeon_helper.dart

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,17 @@ List<MultiFactorInfo> multiFactorInfoPigeonToObject(
1010
return PhoneMultiFactorInfo(
1111
displayName: e.displayName,
1212
enrollmentTimestamp: e.enrollmentTimestamp,
13-
factorId: e.factorId,
13+
// Sometimes can be null on iOS when it shouldn't be.
14+
// Adding default value to prevent null exception.
15+
factorId: e.factorId ?? 'phone',
1416
uid: e.uid,
1517
phoneNumber: e.phoneNumber!,
1618
);
1719
}
1820
return MultiFactorInfo(
1921
displayName: e.displayName,
2022
enrollmentTimestamp: e.enrollmentTimestamp,
21-
factorId: e.factorId,
23+
factorId: e.factorId ?? '',
2224
uid: e.uid,
2325
);
2426
}).toList();

packages/firebase_auth/firebase_auth_platform_interface/lib/src/pigeon/messages.pigeon.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,14 @@ class PigeonMultiFactorInfo {
5757
PigeonMultiFactorInfo({
5858
this.displayName,
5959
required this.enrollmentTimestamp,
60-
required this.factorId,
60+
this.factorId,
6161
required this.uid,
6262
this.phoneNumber,
6363
});
6464

6565
String? displayName;
6666
double enrollmentTimestamp;
67-
String factorId;
67+
String? factorId;
6868
String uid;
6969
String? phoneNumber;
7070

@@ -83,7 +83,7 @@ class PigeonMultiFactorInfo {
8383
return PigeonMultiFactorInfo(
8484
displayName: pigeonMap['displayName'] as String?,
8585
enrollmentTimestamp: pigeonMap['enrollmentTimestamp']! as double,
86-
factorId: pigeonMap['factorId']! as String,
86+
factorId: pigeonMap['factorId'] as String?,
8787
uid: pigeonMap['uid']! as String,
8888
phoneNumber: pigeonMap['phoneNumber'] as String?,
8989
);

packages/firebase_auth/firebase_auth_platform_interface/pigeons/messages.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,14 @@ class PigeonMultiFactorInfo {
3939
const PigeonMultiFactorInfo({
4040
this.displayName,
4141
required this.enrollmentTimestamp,
42-
required this.factorId,
42+
this.factorId,
4343
required this.uid,
4444
required this.phoneNumber,
4545
});
4646

4747
final String? displayName;
4848
final double enrollmentTimestamp;
49-
final String factorId;
49+
final String? factorId;
5050
final String uid;
5151
final String? phoneNumber;
5252
}

0 commit comments

Comments
 (0)