diff options
author | Zsika Phillip <protocol86@users.noreply.github.com> | 2017-11-22 08:57:07 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-11-22 08:57:07 -0800 |
commit | bc2d78439a012bca61fd13dd2df97f4d916174b7 (patch) | |
tree | 5e874f2672298e21617848604e2f4e821bf68898 /Firebase | |
parent | 3e592526ec889887874efd0e46ba3cf72f2f6f98 (diff) |
Adds AuthDataResult to signInWithEmailPassword Method (#484)
* Adds AuthDataResult to signInWithEmail:Password
* Addresses comments
* Addresses comments
* addresses more comments
* Fixes broken tests
Diffstat (limited to 'Firebase')
-rw-r--r-- | Firebase/Auth/Source/FIRAuth.m | 57 | ||||
-rw-r--r-- | Firebase/Auth/Source/Public/FIRAuth.h | 33 |
2 files changed, 84 insertions, 6 deletions
diff --git a/Firebase/Auth/Source/FIRAuth.m b/Firebase/Auth/Source/FIRAuth.m index 9020d3f..a104ad8 100644 --- a/Firebase/Auth/Source/FIRAuth.m +++ b/Firebase/Auth/Source/FIRAuth.m @@ -512,9 +512,14 @@ static NSMutableDictionary *gKeychainServiceNameForAppName; password:(NSString *)password completion:(FIRAuthResultCallback)completion { dispatch_async(FIRAuthGlobalWorkQueue(), ^{ - [self signInWithEmail:email - password:password - callback:[self signInFlowAuthResultCallbackByDecoratingCallback:completion]]; + FIRAuthResultCallback decoratedCallback = + [self signInFlowAuthResultCallbackByDecoratingCallback:completion]; + [self internalSignInAndRetrieveDataWithEmail:email + password:password + completion:^(FIRAuthDataResult *_Nullable authResult, + NSError *_Nullable error) { + decoratedCallback(authResult.user, error); + }]; }); } @@ -554,6 +559,37 @@ static NSMutableDictionary *gKeychainServiceNameForAppName; }]; } +- (void)signInAndRetrieveDataWithEmail:(NSString *)email + password:(NSString *)password + completion:(FIRAuthDataResultCallback)completion { + dispatch_async(FIRAuthGlobalWorkQueue(), ^{ + FIRAuthDataResultCallback decoratedCallback = + [self signInFlowAuthDataResultCallbackByDecoratingCallback:completion]; + [self internalSignInAndRetrieveDataWithEmail:email + password:password + completion:decoratedCallback]; + }); +} + +/** @fn internalSignInAndRetrieveDataWithEmail:password:callback: + @brief Signs in using an email address and password. + @param email The user's email address. + @param password The user's password. + @param completion A block which is invoked when the sign in finishes (or is cancelled.) Invoked + asynchronously on the global auth work queue in the future. + @remarks This is the internal counterpart of this method, which uses a callback that does not + update the current user. + */ +- (void)internalSignInAndRetrieveDataWithEmail:(NSString *)email + password:(NSString *)password + completion:(FIRAuthDataResultCallback)completion { + FIREmailPasswordAuthCredential *credentail = + [[FIREmailPasswordAuthCredential alloc] initWithEmail:email password:password]; + [self internalSignInAndRetrieveDataWithCredential:credentail + isReauthentication:NO + callback:completion]; +} + - (void)signInWithCredential:(FIRAuthCredential *)credential completion:(FIRAuthResultCallback)completion { dispatch_async(FIRAuthGlobalWorkQueue(), ^{ @@ -595,9 +631,18 @@ static NSMutableDictionary *gKeychainServiceNameForAppName; password:emailPasswordCredential.password callback:^(FIRUser *_Nullable user, NSError *_Nullable error) { if (callback) { - FIRAuthDataResult *result = user ? - [[FIRAuthDataResult alloc] initWithUser:user additionalUserInfo:nil] : nil; - callback(result, error); + if (error) { + callback(nil, error); + return; + } + FIRAdditionalUserInfo *additionalUserInfo = + [[FIRAdditionalUserInfo alloc] initWithProviderID:FIREmailAuthProviderID + profile:nil + username:nil + isNewUser:NO]; + FIRAuthDataResult *result = [[FIRAuthDataResult alloc] initWithUser:user + additionalUserInfo:additionalUserInfo]; + callback(result, nil); } }]; return; diff --git a/Firebase/Auth/Source/Public/FIRAuth.h b/Firebase/Auth/Source/Public/FIRAuth.h index 1aa4bcf..9a115ee 100644 --- a/Firebase/Auth/Source/Public/FIRAuth.h +++ b/Firebase/Auth/Source/Public/FIRAuth.h @@ -329,6 +329,39 @@ FIR_SWIFT_NAME(Auth) password:(NSString *)password completion:(nullable FIRAuthResultCallback)completion; +/** @fn signInAndRetrieveDataWithEmail:password:completion: + @brief Signs in using an email address and password. + + @param email The user's email address. + @param password The user's password. + @param completion Optionally; a block which is invoked when the sign in flow finishes, or is + canceled. Invoked asynchronously on the main thread in the future. + + @remarks Possible error codes: + + <ul> + <li>@c FIRAuthErrorCodeOperationNotAllowed - Indicates that email and password + accounts are not enabled. Enable them in the Auth section of the + Firebase console. + </li> + <li>@c FIRAuthErrorCodeUserDisabled - Indicates the user's account is disabled. + </li> + <li>@c FIRAuthErrorCodeWrongPassword - Indicates the user attempted + sign in with an incorrect password. + </li> + <li>@c FIRAuthErrorCodeInvalidEmail - Indicates the email address is malformed. + </li> + </ul> + + @remarks See @c FIRAuthErrors for a list of error codes that are common to all API methods. + @remarks This method will only exist until the next major Firebase release following 4.x.x. + After the next major release the method @c signInWithEmail:password:completion: will support + the @c FIRAuthDataResultCallback. + */ +- (void)signInAndRetrieveDataWithEmail:(NSString *)email + password:(NSString *)password + completion:(nullable FIRAuthDataResultCallback)completion; + /** @fn signInWithCredential:completion: @brief Convenience method for @c signInAndRetrieveDataWithCredential:completion: This method doesn't return additional identity provider data. |