aboutsummaryrefslogtreecommitdiffhomepage
path: root/Firebase
diff options
context:
space:
mode:
authorGravatar Zsika Phillip <protocol86@users.noreply.github.com>2017-06-01 18:12:09 -0700
committerGravatar GitHub <noreply@github.com>2017-06-01 18:12:09 -0700
commit439c29108e60da2f8cc70d8aec7b6ba21e51516d (patch)
tree840822f4248f1c64ce7d1ecfb042638ddf55b7aa /Firebase
parent51ed6b0a4fbdea5db5f57dcdd50e13463d652485 (diff)
Handle missing email error (#54)
Adds appropriate error handling for missing email in the createUserWithEmail:password:completion: flow. Also fixes a few typos.
Diffstat (limited to 'Firebase')
-rw-r--r--Firebase/Auth/Source/FIRAuth.m6
-rw-r--r--Firebase/Auth/Source/FIRAuthErrorUtils.m13
-rw-r--r--Firebase/Auth/Source/FIRAuthErrors.h6
-rw-r--r--Firebase/Auth/Source/Private/FIRAuthErrorUtils.h6
-rw-r--r--Firebase/Auth/Source/Private/FIRAuthInternalErrors.h5
5 files changed, 34 insertions, 2 deletions
diff --git a/Firebase/Auth/Source/FIRAuth.m b/Firebase/Auth/Source/FIRAuth.m
index e844d32..5b1da8c 100644
--- a/Firebase/Auth/Source/FIRAuth.m
+++ b/Firebase/Auth/Source/FIRAuth.m
@@ -93,7 +93,7 @@ static NSString *const kUserKey = @"%@_firebase_user";
/** @var kMissingEmailInvalidParameterExceptionReason
@brief The key of missing email key @c invalidParameterException.
*/
-static NSString *const kEmailInvalidParameterReason = @"The email used to initiate user password "
+static NSString *const kEmailInvalidParameterReason = @"The email used to initiate password reset "
"cannot be nil";
static NSString *const kPasswordResetRequestType = @"PASSWORD_RESET";
@@ -650,6 +650,10 @@ static NSMutableDictionary *gKeychainServiceNameForAppName;
weakPasswordErrorWithServerResponseReason:kMissingPasswordReason]);
return;
}
+ if (![request.email length]) {
+ decoratedCallback(nil, [FIRAuthErrorUtils missingEmail]);
+ return;
+ }
[FIRAuthBackend signUpNewUser:request
callback:^(FIRSignUpNewUserResponse *_Nullable response,
NSError *_Nullable error) {
diff --git a/Firebase/Auth/Source/FIRAuthErrorUtils.m b/Firebase/Auth/Source/FIRAuthErrorUtils.m
index 6764c45..92cc78a 100644
--- a/Firebase/Auth/Source/FIRAuthErrorUtils.m
+++ b/Firebase/Auth/Source/FIRAuthErrorUtils.m
@@ -217,6 +217,11 @@ static NSString *const kFIRAuthErrorMessageInvalidSender = @"The email template
static NSString *const kFIRAuthErrorMessageInvalidRecipientEmail = @"The action code is invalid. "
"This can happen if the code is malformed, expired, or has already been used.";
+/** @var kFIRAuthErrorMessageMissingEmail
+ @brief Message for @c FIRAuthErrorCodeMissingEmail error code.
+ */
+static NSString *const kFIRAuthErrorMessageMissingEmail = @"An email address must be provided.";
+
/** @var kFIRAuthErrorMessageMissingContinueURI
@brief Message for @c FIRAuthErrorCodeMissingContinueURI error code.
*/
@@ -381,6 +386,8 @@ static NSString *FIRAuthErrorDescription(FIRAuthErrorCode code) {
return kFIRAuthErrorMessageInvalidMessagePayload;
case FIRAuthErrorCodeInvalidRecipientEmail:
return kFIRAuthErrorMessageInvalidRecipientEmail;
+ case FIRAuthErrorCodeMissingEmail:
+ return kFIRAuthErrorMessageMissingEmail;
case FIRAuthErrorCodeMissingPhoneNumber:
return kFIRAuthErrorMessageMissingPhoneNumber;
case FIRAuthErrorCodeInvalidPhoneNumber:
@@ -474,6 +481,8 @@ static NSString *const FIRAuthErrorCodeString(FIRAuthErrorCode code) {
return @"ERROR_INVALID_SENDER";
case FIRAuthErrorCodeInvalidRecipientEmail:
return @"ERROR_INVALID_RECIPIENT_EMAIL";
+ case FIRAuthErrorCodeMissingEmail:
+ return @"MISSING_EMAIL";
case FIRAuthErrorCodeMissingPhoneNumber:
return @"ERROR_MISSING_PHONE_NUMBER";
case FIRAuthErrorCodeInvalidPhoneNumber:
@@ -731,6 +740,10 @@ static NSString *const FIRAuthErrorCodeString(FIRAuthErrorCode code) {
return [self errorWithCode:FIRAuthInternalErrorCodeInvalidRecipientEmail message:message];
}
++ (NSError *)missingEmail {
+ return [self errorWithCode:FIRAuthInternalErrorCodeMissingEmail];
+}
+
+ (NSError *)missingPhoneNumberErrorWithMessage:(nullable NSString *)message {
return [self errorWithCode:FIRAuthInternalErrorCodeMissingPhoneNumber message:message];
}
diff --git a/Firebase/Auth/Source/FIRAuthErrors.h b/Firebase/Auth/Source/FIRAuthErrors.h
index 8a35ff5..0b161f7 100644
--- a/Firebase/Auth/Source/FIRAuthErrors.h
+++ b/Firebase/Auth/Source/FIRAuthErrors.h
@@ -184,7 +184,11 @@ typedef NS_ENUM(NSInteger, FIRAuthErrorCode) {
*/
FIRAuthErrorCodeInvalidRecipientEmail = 17033,
- // The enum values between 17033 and 17041 are reserved and should NOT be used for new error
+ /** Indicates that an email address was expected but one was not provided.
+ */
+ FIRAuthErrorCodeMissingEmail = 17034,
+
+ // The enum values between 17034 and 17041 are reserved and should NOT be used for new error
// codes.
/** Indicates that a phone number was not provided in a call to
diff --git a/Firebase/Auth/Source/Private/FIRAuthErrorUtils.h b/Firebase/Auth/Source/Private/FIRAuthErrorUtils.h
index e2ad4aa..e8eb1f5 100644
--- a/Firebase/Auth/Source/Private/FIRAuthErrorUtils.h
+++ b/Firebase/Auth/Source/Private/FIRAuthErrorUtils.h
@@ -313,6 +313,12 @@ NS_ASSUME_NONNULL_BEGIN
*/
+ (NSError *)invalidRecipientEmailErrorWithMessage:(nullable NSString *)message;
+/** @fn missingEmail
+ @brief Constructs an @c NSError with the @c FIRAuthErrorCodeMissingEmail code.
+ @return The NSError instance associated with the given FIRAuthError.
+ */
++ (NSError *)missingEmail;
+
/** @fn missingPhoneNumberErrorWithMessage:
@brief Constructs an @c NSError with the @c FIRAuthErrorCodeMissingPhoneNumber code.
@param message Error message from the backend, if any.
diff --git a/Firebase/Auth/Source/Private/FIRAuthInternalErrors.h b/Firebase/Auth/Source/Private/FIRAuthInternalErrors.h
index 7eebbde..c0fc912 100644
--- a/Firebase/Auth/Source/Private/FIRAuthInternalErrors.h
+++ b/Firebase/Auth/Source/Private/FIRAuthInternalErrors.h
@@ -238,6 +238,11 @@ typedef NS_ENUM(NSInteger, FIRAuthInternalErrorCode) {
FIRAuthInternalErrorCodeInvalidRecipientEmail =
FIRAuthPublicErrorCodeFlag | FIRAuthErrorCodeInvalidRecipientEmail,
+ /** Indicates that an email address was expected but one was not provided.
+ */
+ FIRAuthInternalErrorCodeMissingEmail =
+ FIRAuthPublicErrorCodeFlag | FIRAuthErrorCodeMissingEmail,
+
/** Indicates that a phone number was not provided in a call to @c verifyPhoneNumber:completion:.
*/
FIRAuthInternalErrorCodeMissingPhoneNumber =