aws-sdk-ios icon indicating copy to clipboard operation
aws-sdk-ios copied to clipboard

Cognito update attribute return success but codeDeliveryDetailsList is nil

Open hrvoje0099 opened this issue 2 years ago • 2 comments

State your question I’m trying to update email atrribute, but I dont get verification code on email. Response is success, but codeDeliveryDetailsList is nil. Why? What that mean?

This is my code:

let emailAttribute = AWSCognitoIdentityUserAttributeType(name: "email", value: newEmail)
let attributes = [emailAttribute]
cognitoPool?.currentUser()?.update(attributes).continueWith { [weak self] response in
   guard let self = self else { return nil }

   if let error = response.error as? NSError {
      print("Cognito error - update email attribute: \(error)")
      self.processCognitoError(error)
   } else {
      DispatchQueue.main.async {
         self.didContinueToEmailVerifyScreen?()
      }

      print(response.result?.codeDeliveryDetailsList)
   }
   return nil
}

Which AWS Services are you utilizing? Cognito

Environment(please complete the following information):

  • SDK Version: 2.27.13
  • Dependency Manager: SPM
  • Swift Version : 5

hrvoje0099 avatar Aug 09 '22 13:08 hrvoje0099

@hrvoje0099 This feels like that you succeeded to update your email using the API. codeDeliveryDetailsList will only have a value if its required to confirm an attribute. In your case it feels like Cognito is not setup to verify emails. Please refer to the screenshot attached. In your case, it feels like the value is set to No Verification.

image

harsh62 avatar Aug 10 '22 19:08 harsh62

@harsh62 Yes as I wrote, response is success but I don’t get verification code on email and codeDeliveryDetailsList is nil. Verify is set to email: image

hrvoje0099 avatar Aug 11 '22 07:08 hrvoje0099

@hrvoje0099 Can you please share the verbose logs of the request by adding the following changes.

Import AWSCore module

import AWSCore

and then enable verbose loggin.

AWSDDLog.sharedInstance.add(AWSDDTTYLogger())
AWSDDLog.sharedInstance.logLevel = .verbose

harsh62 avatar Aug 15 '22 14:08 harsh62

@harsh62 This is logs:

2022-08-15 16:51:42:243 GameStar[7034:314998] Request headers:
{
    "Content-Type" = "application/x-amz-json-1.1";
    Host = "cognito-idp.eu-central-1.amazonaws.com";
    "User-Agent" = "aws-sdk-iOS/2.27.13 iOS/15.5 hr-US";
    "X-Amz-Date" = 20220815T145142Z;
    "X-Amz-Target" = "AWSCognitoIdentityProviderService.UpdateUserAttributes";
}
2022-08-15 16:51:42:243 GameStar[7034:314998] Request body:
{"UserAttributes":[{"Value":"[email protected]","Name":"email"}],"AccessToken":"XXX"}
2022-08-15 16:51:42:424 GameStar[7034:315228] Response headers:
{
    "Content-Length" = 2;
    "Content-Type" = "application/x-amz-json-1.1";
    Date = "Mon, 15 Aug 2022 14:51:42 GMT";
    "x-amzn-requestid" = "53a70e1e-9bcf-439f-b9bf-ca9042320f3c";
}
2022-08-15 16:51:42:425 GameStar[7034:315228] Response body:
{}
Success cognito - update email attribute! 
Details: nil

hrvoje0099 avatar Aug 15 '22 14:08 hrvoje0099

@hrvoje0099 Thanks for the information. I will investigate further..

Please always remember to redact sensitive information like accessTokens and email in this case.

harsh62 avatar Aug 15 '22 16:08 harsh62

@hrvoje0099 I wanted to ask if email gets updated on Cognito even though you never got a code?

harsh62 avatar Sep 16 '22 18:09 harsh62

@harsh62 I noticed that this problem happens to me if I try to update with the same email.

hrvoje0099 avatar Sep 16 '22 18:09 hrvoje0099

@hrvoje0099 Then in that case it is expected. Because no real update happened in Cognito.

harsh62 avatar Sep 16 '22 19:09 harsh62