Cognito seems to be going through changes recently, I have one user pool made in the old UI (if there is a way to get back please tell me, the new UI is horrible and doesn’t allow to choose specific settings).
I have the following code:
const secretHash = calculateSecretHash(
email,
COGNITO_CLIENT_ID,
COGNITO_CLIENT_SECRET,
)
const signUpCommand = new SignUpCommand({
ClientId: COGNITO_CLIENT_ID,
Username: email,
Password: password,
SecretHash: secretHash,
UserAttributes: [
{ Name: 'email', Value: email },
{ Name: 'name', Value: firstName },
{ Name: 'family_name', Value: lastName },
{ Name: 'birthdate', Value: `01/01/${birthYear}` },
{
Name: 'custom:nl__ESOffers',
Value: newsletters.includes('nl__ESOffers') ? 'true' : 'false',
},
],
})
signUpResponse = await getCognitoClient().send(signUpCommand)
// Add a delay to allow user creation to propagate
await new Promise((resolve) => setTimeout(resolve, 2000))
// Now set the externalId
// Getting called too soon apparently, error response here
await adminUpdateUser({
UserSub: signUpResponse.UserSub,
attributes: {
externalId: signUpResponse.UserSub,
},
})
The signUp commanded is successful, so therefore the assumption is the user exists, however based on the signup response I want to update the user with a custom attribute. at this point the user does not exists and I get the following error:
Error updating user: UserNotFoundException: User does not exist.
All this used to work on the old userpool, however on the new user pool created under the new UI this no longer works.
We have also had to create the secret hash due to no longer being allowed to have that turned off for app clients as the old UI allowed.
I have added a delay as can be seen in the code which doesn’t help either. Any other suggestions or help that might solve this would be greatly appreciated.