Skip to content

Commit 9ea83c8

Browse files
author
chuanr
authored
Persist FIRPhoneMultiFactorInfo (instead of FIRMultiFactorInfo) so that full phone number is always cached (#10296)
1 parent 5af4ae2 commit 9ea83c8

File tree

3 files changed

+30
-2
lines changed

3 files changed

+30
-2
lines changed

FirebaseAuth/Sources/MultiFactor/FIRMultiFactor.m

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,8 +179,7 @@ - (nullable instancetype)initWithCoder:(NSCoder *)aDecoder {
179179
self = [self init];
180180
if (self) {
181181
NSArray<FIRMultiFactorInfo *> *enrolledFactors =
182-
[aDecoder decodeObjectOfClass:[NSArray<FIRMultiFactorInfo *> class]
183-
forKey:kEnrolledFactorsCodingKey];
182+
[aDecoder decodeObjectForKey:kEnrolledFactorsCodingKey];
184183
_enrolledFactors = enrolledFactors;
185184
_user = [aDecoder decodeObjectOfClass:[FIRUser class] forKey:kUserCodingKey];
186185
}

FirebaseAuth/Sources/MultiFactor/FIRMultiFactorInfo+Internal.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,14 @@ NS_ASSUME_NONNULL_BEGIN
3030

3131
- (instancetype)initWithProto:(FIRAuthProtoMFAEnrollment *)proto;
3232

33+
#pragma mark - NSSecureCoding
34+
// Note that we're not able to indicate FIRMultiFactorInfo conforming to NSSecureCoding in an
35+
// internal header file, so the following NSSecureCoding methods are explicitly declared.
36+
37+
- (nullable instancetype)initWithCoder:(NSCoder *)aDecoder;
38+
39+
- (void)encodeWithCoder:(NSCoder *)aCoder;
40+
3341
@end
3442

3543
NS_ASSUME_NONNULL_END

FirebaseAuth/Sources/MultiFactor/Phone/FIRPhoneMultiFactorInfo.m

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
#import "FirebaseAuth/Sources/Backend/RPC/Proto/FIRAuthProtoMFAEnrollment.h"
2424
#import "FirebaseAuth/Sources/MultiFactor/FIRMultiFactorInfo+Internal.h"
2525

26+
static NSString *kPhoneNumberCodingKey = @"phoneNumber";
27+
2628
extern NSString *const FIRPhoneMultiFactorID;
2729

2830
@implementation FIRPhoneMultiFactorInfo
@@ -36,6 +38,25 @@ - (instancetype)initWithProto:(FIRAuthProtoMFAEnrollment *)proto {
3638
return self;
3739
}
3840

41+
#pragma mark - NSSecureCoding
42+
43+
+ (BOOL)supportsSecureCoding {
44+
return YES;
45+
}
46+
47+
- (nullable instancetype)initWithCoder:(NSCoder *)aDecoder {
48+
self = [super initWithCoder:aDecoder];
49+
if (self) {
50+
_phoneNumber = [aDecoder decodeObjectOfClass:[NSString class] forKey:kPhoneNumberCodingKey];
51+
}
52+
return self;
53+
}
54+
55+
- (void)encodeWithCoder:(NSCoder *)aCoder {
56+
[super encodeWithCoder:aCoder];
57+
[aCoder encodeObject:_phoneNumber forKey:kPhoneNumberCodingKey];
58+
}
59+
3960
@end
4061

4162
#endif

0 commit comments

Comments
 (0)