Skip to content

Commit 1b92fac

Browse files
author
Chuan Ren
committed
Fix pr issues
1 parent ea7409d commit 1b92fac

File tree

6 files changed

+73
-60
lines changed

6 files changed

+73
-60
lines changed

Auth/FirebaseAuthUI/FUIAuthBaseViewController_Internal.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ NS_ASSUME_NONNULL_BEGIN
4040

4141
/** @fn showAlertWithMessage:
4242
@brief Displays an alert view with given title and message on top of the current view
43-
controller.
43+
controller.
4444
@param message The message of the alert.
4545
*/
4646
+ (void)showAlertWithMessage:(NSString *)message;

EmailAuth/FirebaseEmailAuthUI/FUIConfirmEmailViewController.m

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@ - (instancetype)initWithAuthUI:(FUIAuth *)authUI {
8585
- (instancetype)initWithNibName:(NSString *)nibNameOrNil
8686
bundle:(NSBundle *)nibBundleOrNil
8787
authUI:(FUIAuth *)authUI {
88-
8988
self = [super initWithNibName:nibNameOrNil
9089
bundle:nibBundleOrNil
9190
authUI:authUI];

EmailAuth/FirebaseEmailAuthUI/FUIEmailAuth.m

Lines changed: 46 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -229,28 +229,36 @@ - (BOOL)handleOpenURL:(NSURL *)URL sourceApplication:(nullable NSString *)source
229229
}
230230
// Retrieve parameters from local storage
231231
NSMutableDictionary *localParameterDict = [NSMutableDictionary dictionary];
232-
localParameterDict[kEmailLinkSignInEmailKey] = [GULUserDefaults.standardUserDefaults stringForKey:kEmailLinkSignInEmailKey];
232+
localParameterDict[kEmailLinkSignInEmailKey] = [GULUserDefaults.standardUserDefaults
233+
stringForKey:kEmailLinkSignInEmailKey];
233234
localParameterDict[@"ui_sid"] = [GULUserDefaults.standardUserDefaults stringForKey:@"ui_sid"];
234235

235236
// Handling flows
236237
NSString *urlSessionID = urlParameterDict[@"ui_sid"];
237238
NSString *localSessionID = localParameterDict[@"ui_sid"];
238239
BOOL sameDevice = urlSessionID && localSessionID && [urlSessionID isEqualToString:localSessionID];
239240

240-
if (sameDevice) { // Same device
241-
if (urlParameterDict[@"ui_pid"] != nil) { // Unverified provider linking
241+
if (sameDevice) {
242+
// Same device
243+
if (urlParameterDict[@"ui_pid"]) {
244+
// Unverified provider linking
242245
[self handleUnverifiedProviderLinking:urlParameterDict[@"ui_pid"]
243246
email:localParameterDict[kEmailLinkSignInEmailKey]];
244-
} else if (urlParameterDict[@"ui_auid"] != nil) { // Anonymous upgrade
247+
} else if (urlParameterDict[@"ui_auid"]) {
248+
// Anonymous upgrade
245249
[self handleAnonymousUpgrade:urlParameterDict[@"ui_auid"]
246250
email:localParameterDict[kEmailLinkSignInEmailKey]];
247-
} else { // Normal email link sign in
251+
} else {
252+
// Normal email link sign in
248253
[self handleEmaiLinkSignIn:localParameterDict[kEmailLinkSignInEmailKey]];
249254
}
250-
} else { // Different device
251-
if ([urlParameterDict[@"ui_sd"] isEqualToString:@"1"]) { // Force same device enabled
255+
} else {
256+
// Different device
257+
if ([urlParameterDict[@"ui_sd"] isEqualToString:@"1"]) {
258+
// Force same device enabled
252259
[self handleDifferentDevice];
253-
} else { // Force same device not enabled
260+
} else {
261+
// Force same device not enabled
254262
[self handleConfirmEmail];
255263
}
256264
}
@@ -261,8 +269,10 @@ - (BOOL)handleOpenURL:(NSURL *)URL sourceApplication:(nullable NSString *)source
261269
- (void)handleUnverifiedProviderLinking:(NSString *)providerID
262270
email:(NSString *)email {
263271
if ([providerID isEqualToString:FIRFacebookAuthProviderID]) {
264-
NSData *unverifiedProviderCredentialData = [GULUserDefaults.standardUserDefaults objectForKey:kEmailLinkSignInLinkingCredentialKey];
265-
FIRAuthCredential *unverifiedProviderCredential = [NSKeyedUnarchiver unarchiveObjectWithData:unverifiedProviderCredentialData];
272+
NSData *unverifiedProviderCredentialData = [GULUserDefaults.standardUserDefaults
273+
objectForKey:kEmailLinkSignInLinkingCredentialKey];
274+
FIRAuthCredential *unverifiedProviderCredential =
275+
[NSKeyedUnarchiver unarchiveObjectWithData:unverifiedProviderCredentialData];
266276

267277
FIRAuthCredential *emailLinkCredential =
268278
[FIREmailAuthProvider credentialWithEmail:email link:self.emailLink];
@@ -663,34 +673,36 @@ - (void)handleAccountLinkingForEmail:(NSString *)email
663673
"link below. \n \n For this flow to successfully connect your "
664674
"account with this email, you have to open the link on the same "
665675
"device or browser.", email, providerName, email];
676+
void (^actionHandler)(void) = ^() {
677+
[self generateURLParametersAndLocalCache:email
678+
linkingProvider:newCredential.provider];
679+
680+
NSData *data = [NSKeyedArchiver archivedDataWithRootObject:newCredential];
681+
[GULUserDefaults.standardUserDefaults setObject:data forKey:kEmailLinkSignInLinkingCredentialKey];
682+
683+
void (^completion)(NSError * _Nullable error) = ^(NSError * _Nullable error){
684+
if (error) {
685+
[FUIAuthBaseViewController showAlertWithMessage:error.description];
686+
} else {
687+
NSString *signInMessage = [NSString stringWithFormat:
688+
@"A sign-in email with additional instrucitons was sent to %@. Check your "
689+
"email to complete sign-in.", email];
690+
[FUIAuthBaseViewController
691+
showAlertWithTitle:@"Sign-in email sent"
692+
message:signInMessage
693+
presentingViewController:nil];
694+
}
695+
};
696+
[self.authUI.auth sendSignInLinkToEmail:email
697+
actionCodeSettings:self.actionCodeSettings
698+
completion:completion];
699+
};
700+
666701
[FUIAuthBaseViewController
667702
showAlertWithTitle:@"Sign in"
668703
message:message
669704
actionTitle:@"Sign in"
670-
actionHandler:^{
671-
[self generateURLParametersAndLocalCache:email
672-
linkingProvider:newCredential.provider];
673-
674-
NSData *data = [NSKeyedArchiver archivedDataWithRootObject:newCredential];
675-
[GULUserDefaults.standardUserDefaults setObject:data forKey:kEmailLinkSignInLinkingCredentialKey];
676-
677-
void (^completion)(NSError * _Nullable error) = ^(NSError * _Nullable error){
678-
if (error) {
679-
[FUIAuthBaseViewController showAlertWithMessage:error.description];
680-
} else {
681-
NSString *signInMessage = [NSString stringWithFormat:
682-
@"A sign-in email with additional instrucitons was sent to %@. Check your "
683-
"email to complete sign-in.", email];
684-
[FUIAuthBaseViewController
685-
showAlertWithTitle:@"Sign-in email sent"
686-
message:signInMessage
687-
presentingViewController:nil];
688-
}
689-
};
690-
[self.authUI.auth sendSignInLinkToEmail:email
691-
actionCodeSettings:self.actionCodeSettings
692-
completion:completion];
693-
}
705+
actionHandler:actionHandler
694706
dismissTitle:nil
695707
dismissHandler:nil
696708
presentingViewController:nil];
@@ -769,10 +781,8 @@ - (void)generateURLParametersAndLocalCache:(NSString *)email linkingProvider:(NS
769781
NSURLComponents *urlComponents = [NSURLComponents componentsWithString:url.absoluteString];
770782
NSMutableArray<NSURLQueryItem *> *urlQuertItems = [NSMutableArray array];
771783

772-
// kEmailLinkSignInEmailKey
773784
[GULUserDefaults.standardUserDefaults setObject:email forKey:kEmailLinkSignInEmailKey];
774785

775-
// ui_auid
776786
if (self.authUI.auth.currentUser.isAnonymous && self.authUI.shouldAutoUpgradeAnonymousUsers) {
777787
NSString *auid = self.authUI.auth.currentUser.uid;
778788

@@ -781,7 +791,6 @@ - (void)generateURLParametersAndLocalCache:(NSString *)email linkingProvider:(NS
781791
[urlQuertItems addObject:anonymousUserIDQueryItem];
782792
}
783793

784-
// ui_sid
785794
NSInteger ui_sid = arc4random_uniform(999999999);
786795
NSString *sidString = [NSString stringWithFormat:@"%ld", (long)ui_sid];
787796
[GULUserDefaults.standardUserDefaults setObject:sidString forKey:@"ui_sid"];
@@ -790,7 +799,6 @@ - (void)generateURLParametersAndLocalCache:(NSString *)email linkingProvider:(NS
790799
[NSURLQueryItem queryItemWithName:@"ui_sid" value:sidString];
791800
[urlQuertItems addObject:sessionIDQueryItem];
792801

793-
// ui_sd
794802
NSString *sameDeviceValueString;
795803
if (self.forceSameDevice) {
796804
sameDeviceValueString = @"1";
@@ -800,7 +808,6 @@ - (void)generateURLParametersAndLocalCache:(NSString *)email linkingProvider:(NS
800808
NSURLQueryItem *sameDeviceQueryItem = [NSURLQueryItem queryItemWithName:@"ui_sd" value:sameDeviceValueString];
801809
[urlQuertItems addObject:sameDeviceQueryItem];
802810

803-
// ui_pid
804811
if (linkingProvider) {
805812
NSURLQueryItem *providerIDQueryItem = [NSURLQueryItem queryItemWithName:@"ui_pid" value:linkingProvider];
806813
[urlQuertItems addObject:providerIDQueryItem];

EmailAuth/FirebaseEmailAuthUI/FUIEmailEntryViewController.m

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -264,8 +264,7 @@ - (void)sendSignInLinkToEmail:(NSString*)email {
264264
dismissHandler:^{
265265
[self.navigationController popToRootViewControllerAnimated:YES];
266266
}
267-
presentingViewController:self
268-
];
267+
presentingViewController:self];
269268
}
270269
}];
271270
}

samples/objc/FirebaseUI-demo-objc/FUIAppDelegate.m

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@
2727

2828
@implementation FUIAppDelegate
2929

30-
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
30+
- (BOOL)application:(UIApplication *)application
31+
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
3132
if (kTwitterConsumerKey.length && kTwitterConsumerSecret.length) {
3233
[[TWTRTwitter sharedInstance] startWithConsumerKey:kTwitterConsumerKey
3334
consumerSecret:kTwitterConsumerSecret];
@@ -38,32 +39,40 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
3839
return YES;
3940
}
4041

41-
- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<NSString*, id> *)options {
42+
- (BOOL)application:(UIApplication *)app
43+
openURL:(NSURL *)url
44+
options:(NSDictionary<NSString*, id> *)options {
4245
NSString *sourceApplication = options[UIApplicationOpenURLOptionsSourceApplicationKey];
4346
return [self handleOpenUrl:url sourceApplication:sourceApplication];
4447
}
4548

46-
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(nullable NSString *)sourceApplication annotation:(id)annotation {
49+
- (BOOL)application:(UIApplication *)application
50+
openURL:(NSURL *)url
51+
sourceApplication:(nullable NSString *)sourceApplication
52+
annotation:(id)annotation {
4753
return [self handleOpenUrl:url sourceApplication:sourceApplication];
4854
}
4955

50-
- (BOOL)application:(UIApplication *)application continueUserActivity:(nonnull NSUserActivity *)userActivity restorationHandler:
56+
- (BOOL)application:(UIApplication *)application
57+
continueUserActivity:(nonnull NSUserActivity *)userActivity
58+
restorationHandler:
5159
#if defined(__IPHONE_12_0) && (__IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_12_0)
5260
(nonnull void (^)(NSArray<id<UIUserActivityRestoring>> *_Nullable))restorationHandler {
5361
#else
5462
(nonnull void (^)(NSArray *_Nullable))restorationHandler {
5563
#endif // __IPHONE_12_0
56-
BOOL handled = [[FIRDynamicLinks dynamicLinks] handleUniversalLink:userActivity.webpageURL
57-
completion:^(FIRDynamicLink * _Nullable dynamicLink,
58-
NSError * _Nullable error) {
59-
if (error) {
60-
NSLog(@"%@", error.description);
61-
} else {
62-
[self handleOpenUrl:dynamicLink.url sourceApplication:nil];
63-
}
64-
}];
65-
return handled;
66-
}
64+
BOOL handled = [[FIRDynamicLinks dynamicLinks]
65+
handleUniversalLink:userActivity.webpageURL
66+
completion:^(FIRDynamicLink * _Nullable dynamicLink,
67+
NSError * _Nullable error) {
68+
if (error) {
69+
NSLog(@"%@", error.description);
70+
} else {
71+
[self handleOpenUrl:dynamicLink.url sourceApplication:nil];
72+
}
73+
}];
74+
return handled;
75+
}
6776

6877
- (BOOL)handleOpenUrl:(NSURL *)url sourceApplication:(nullable NSString *)sourceApplication {
6978
if ([FUIAuth.defaultAuthUI handleOpenURL:url sourceApplication:sourceApplication]) {

samples/objc/FirebaseUI-demo-objc/Samples/Auth/FUIAuthViewController.m

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -373,9 +373,8 @@ + (NSArray *)getListOfIDPs:(NSArray<NSIndexPath *> *)selectedRows
373373
if (useEmaiLink) {
374374
// ActionCodeSettings for email link sign-in.
375375
FIRActionCodeSettings *actionCodeSettings = [[FIRActionCodeSettings alloc] init];
376-
[actionCodeSettings setURL:[NSURL URLWithString:@"https://fb-sa-1211.appspot.com"]];
376+
actionCodeSettings.URL = [NSURL URLWithString:@"https://fb-sa-1211.appspot.com"];
377377
actionCodeSettings.handleCodeInApp = YES;
378-
[actionCodeSettings setIOSBundleID:[[NSBundle mainBundle] bundleIdentifier]];
379378
[actionCodeSettings setAndroidPackageName:@"com.example.android"
380379
installIfNotAvailable:NO
381380
minimumVersion:@"12"];

0 commit comments

Comments
 (0)