|
91 | 91 | */
|
92 | 92 | static NSString *const kSignInGoogleButtonText = @"Sign in with Google";
|
93 | 93 |
|
| 94 | +/** @var kSignInWithEmailLink |
| 95 | + @brief The text of the "Sign in with Email Link" button. |
| 96 | + */ |
| 97 | +static NSString *const kSignInWithEmailLink = @"Sign in with Email Link"; |
| 98 | + |
| 99 | +/** @var kSendEmailSignInLink |
| 100 | + @brief The text of the "Send Email SignIn link" button |
| 101 | +*/ |
| 102 | +static NSString *const kSendEmailSignInLink = @"Send Email Sign in Link"; |
| 103 | + |
94 | 104 | /** @var kSignInAndRetrieveGoogleButtonText
|
95 | 105 | @brief The text of the "Sign in with Google and retrieve data" button.
|
96 | 106 | */
|
|
279 | 289 | */
|
280 | 290 | static NSString *const kGetProvidersForEmail = @"Get Provider IDs for Email";
|
281 | 291 |
|
| 292 | +/** @var kGetAllSignInMethodsForEmail |
| 293 | + @brief The text of the "Get sign-in methods for Email" button. |
| 294 | + */ |
| 295 | +static NSString *const kGetAllSignInMethodsForEmail = @"Get Sign-in methods for Email"; |
| 296 | + |
282 | 297 | /** @var kActionCodeTypeDescription
|
283 | 298 | @brief The description of the "Action Type" entry.
|
284 | 299 | */
|
@@ -722,6 +737,10 @@ - (void)updateTable {
|
722 | 737 | action:^{ [weakSelf createUserAuthDataResult]; }],
|
723 | 738 | [StaticContentTableViewCell cellWithTitle:kSignInGoogleButtonText
|
724 | 739 | action:^{ [weakSelf signInGoogle]; }],
|
| 740 | + [StaticContentTableViewCell cellWithTitle:kSignInWithEmailLink |
| 741 | + action:^{ [weakSelf signInWithEmailLink]; }], |
| 742 | + [StaticContentTableViewCell cellWithTitle:kSendEmailSignInLink |
| 743 | + action:^{ [weakSelf sendEmailSignInLink]; }], |
725 | 744 | [StaticContentTableViewCell cellWithTitle:kSignInGoogleAndRetrieveDataButtonText
|
726 | 745 | action:^{ [weakSelf signInGoogleAndRetrieveData]; }],
|
727 | 746 | [StaticContentTableViewCell cellWithTitle:kSignInFacebookButtonText
|
@@ -754,6 +773,8 @@ - (void)updateTable {
|
754 | 773 | action:^{ [weakSelf reloadUser]; }],
|
755 | 774 | [StaticContentTableViewCell cellWithTitle:kGetProvidersForEmail
|
756 | 775 | action:^{ [weakSelf getProvidersForEmail]; }],
|
| 776 | + [StaticContentTableViewCell cellWithTitle:kGetAllSignInMethodsForEmail |
| 777 | + action:^{ [weakSelf getAllSignInMethodsForEmail]; }], |
757 | 778 | [StaticContentTableViewCell cellWithTitle:kUpdateEmailText
|
758 | 779 | action:^{ [weakSelf updateEmail]; }],
|
759 | 780 | [StaticContentTableViewCell cellWithTitle:kUpdatePasswordText
|
@@ -1657,7 +1678,7 @@ - (void)signInFacebookAndRetrieveData {
|
1657 | 1678 | }
|
1658 | 1679 |
|
1659 | 1680 | /** @fn signInEmailPassword
|
1660 |
| - @brief Invoked when "sign in with Email/Password" row is pressed. |
| 1681 | + @brief Invoked when "Sign in with Email/Password" row is pressed. |
1661 | 1682 | */
|
1662 | 1683 | - (void)signInEmailPassword {
|
1663 | 1684 | [self showTextInputPromptWithMessage:@"Email Address:"
|
@@ -1724,6 +1745,75 @@ - (void)signInEmailPasswordAuthDataResult {
|
1724 | 1745 | }];
|
1725 | 1746 | }
|
1726 | 1747 |
|
| 1748 | +/** @fn signInWithEmailLink |
| 1749 | + @brief Invoked when "Sign in with email link" row is pressed. |
| 1750 | + */ |
| 1751 | +- (void)signInWithEmailLink { |
| 1752 | + [self showTextInputPromptWithMessage:@"Email Address:" |
| 1753 | + keyboardType:UIKeyboardTypeEmailAddress |
| 1754 | + completionBlock:^(BOOL userPressedOK, NSString *_Nullable email) { |
| 1755 | + if (!userPressedOK || !email.length) { |
| 1756 | + return; |
| 1757 | + } |
| 1758 | + [self showTextInputPromptWithMessage:@"Email Sign-In Link:" |
| 1759 | + completionBlock:^(BOOL userPressedOK, NSString *_Nullable link) { |
| 1760 | + if (!userPressedOK) { |
| 1761 | + return; |
| 1762 | + } |
| 1763 | + if ([[FIRAuth auth] isSignInWithEmailLink:link]) { |
| 1764 | + [self showSpinner:^{ |
| 1765 | + [[AppManager auth] signInWithEmail:email |
| 1766 | + link:link |
| 1767 | + completion:^(FIRAuthDataResult *_Nullable authResult, |
| 1768 | + NSError *_Nullable error) { |
| 1769 | + [self hideSpinner:^{ |
| 1770 | + if (error) { |
| 1771 | + [self logFailure:@"sign-in with Email/Sign-In failed" error:error]; |
| 1772 | + } else { |
| 1773 | + [self logSuccess:@"sign-in with Email/Sign-In link succeeded."]; |
| 1774 | + [self log:[NSString stringWithFormat:@"UID: %@",authResult.user.uid]]; |
| 1775 | + } |
| 1776 | + [self showTypicalUIForUserUpdateResultsWithTitle:@"Sign-In Error" error:error]; |
| 1777 | + }]; |
| 1778 | + }]; |
| 1779 | + }]; |
| 1780 | + } else { |
| 1781 | + [self log:@"The sign-in link is invalid"]; |
| 1782 | + } |
| 1783 | + }]; |
| 1784 | + }]; |
| 1785 | +} |
| 1786 | + |
| 1787 | +/** @fn sendEmailSignInLink |
| 1788 | + @brief Invoked when "Send email sign-in link" row is pressed. |
| 1789 | + */ |
| 1790 | +- (void)sendEmailSignInLink { |
| 1791 | + [self showTextInputPromptWithMessage:@"Email:" |
| 1792 | + completionBlock:^(BOOL userPressedOK, NSString *_Nullable userInput) { |
| 1793 | + if (!userPressedOK) { |
| 1794 | + return; |
| 1795 | + } |
| 1796 | + [self showSpinner:^{ |
| 1797 | + void (^requestEmailSignInLink)(void (^)(NSError *)) = ^(void (^completion)(NSError *)) { |
| 1798 | + [[AppManager auth] sendSignInLinkToEmail:userInput |
| 1799 | + actionCodeSettings:[self actionCodeSettings] |
| 1800 | + completion:completion]; |
| 1801 | + }; |
| 1802 | + requestEmailSignInLink(^(NSError *_Nullable error) { |
| 1803 | + [self hideSpinner:^{ |
| 1804 | + if (error) { |
| 1805 | + [self logFailure:@"Email Link request failed" error:error]; |
| 1806 | + [self showMessagePrompt:error.localizedDescription]; |
| 1807 | + return; |
| 1808 | + } |
| 1809 | + [self logSuccess:@"Email Link request succeeded."]; |
| 1810 | + [self showMessagePrompt:@"Sent"]; |
| 1811 | + }]; |
| 1812 | + }); |
| 1813 | + }]; |
| 1814 | + }]; |
| 1815 | +} |
| 1816 | + |
1727 | 1817 | /** @fn signUpNewEmail
|
1728 | 1818 | @brief Invoked if sign-in is attempted with new email/password.
|
1729 | 1819 | @remarks Should only be called if @c FIRAuthErrorCodeInvalidEmail is encountered on attepmt to
|
@@ -2245,6 +2335,39 @@ - (void)getProvidersForEmail {
|
2245 | 2335 | }];
|
2246 | 2336 | }
|
2247 | 2337 |
|
| 2338 | +/** @fn getAllSignInMethodsForEmail |
| 2339 | + @brief Prompts user for an email address, calls @c FIRAuth.getAllSignInMethodsForEmail:callback: |
| 2340 | + and displays the result. |
| 2341 | + */ |
| 2342 | +- (void)getAllSignInMethodsForEmail { |
| 2343 | + [self showTextInputPromptWithMessage:@"Email:" |
| 2344 | + completionBlock:^(BOOL userPressedOK, NSString *_Nullable userInput) { |
| 2345 | + if (!userPressedOK || !userInput.length) { |
| 2346 | + return; |
| 2347 | + } |
| 2348 | + |
| 2349 | + [self showSpinner:^{ |
| 2350 | + [[AppManager auth] fetchSignInMethodsForEmail:userInput |
| 2351 | + completion:^(NSArray<NSString *> *_Nullable signInMethods, |
| 2352 | + NSError *_Nullable error) { |
| 2353 | + if (error) { |
| 2354 | + [self logFailure:@"get sign-in methods for email failed" error:error]; |
| 2355 | + } else { |
| 2356 | + [self logSuccess:@"get sign-in methods for email succeeded."]; |
| 2357 | + } |
| 2358 | + [self hideSpinner:^{ |
| 2359 | + if (error) { |
| 2360 | + [self showMessagePrompt:error.localizedDescription]; |
| 2361 | + return; |
| 2362 | + } |
| 2363 | + [self showMessagePrompt:[signInMethods componentsJoinedByString:@", "]]; |
| 2364 | + }]; |
| 2365 | + }]; |
| 2366 | + }]; |
| 2367 | + }]; |
| 2368 | +} |
| 2369 | + |
| 2370 | + |
2248 | 2371 | /** @fn actionCodeRequestTypeString
|
2249 | 2372 | @brief Returns a string description for the type of the next action code request.
|
2250 | 2373 | */
|
@@ -2486,6 +2609,8 @@ - (NSString *)nameForActionCodeOperation:(FIRActionCodeOperation)operation {
|
2486 | 2609 | return @"Recover Email";
|
2487 | 2610 | case FIRActionCodeOperationPasswordReset:
|
2488 | 2611 | return @"Password Reset";
|
| 2612 | + case FIRActionCodeOperationEmailLink: |
| 2613 | + return @"Email Sign-In Link"; |
2489 | 2614 | case FIRActionCodeOperationUnknown:
|
2490 | 2615 | return @"Unknown action";
|
2491 | 2616 | }
|
|
0 commit comments