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
질문됨 한 달 전64회 조회
답변 없음

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠