Read/write Cognito custom attributes in React App

0

Hi, I have created a Cognito user pool and later added a custom attribute (custom:encryptionKey). I would like to access the custom field in my React app with fetchUserAttributes. I assume it will only be delivered by fetchUserAttributes if it has some content, right? I tried to set the content by updateUserAttribute, but it failed with TypeError: input.userAttribute is undefined. Do I need to set up my app in a special way to access (read/write) those custom attributes Any help is appreciated. Best wishes Frank J.


    if (!encryptionKeyAttribute) {
      console.log("No encryption key found, generating one...");
      const newKey = generateEncryptionKey();
      console.log("New Key Generated and Saved1:", newKey);
      await handleUpdateUserAttribute("custom:encryptionKey", newKey);
      console.log("New Key Generated and Saved2:", newKey);
      return newKey;
    }

    return encryptionKeyAttribute;
  } catch (error) {
    console.error("Error handling the encryption key:", error);
    throw new Error("Failed to ensure encryption key.");
  }
};

// Funktion zur Aktualisierung des Benutzerattributs
async function handleUpdateUserAttribute(attributeKey, value) {
  try {
    const output = await updateUserAttribute({ attributeKey, value });
    await handleUpdateUserAttributeNextSteps(output);
  } catch (error) {
    console.error("Error updating user attribute:", error);
    throw new Error("Failed to update user attribute.");
  }
}
Frank J
asked 16 days ago55 views
No Answers

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions