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
已提問 1 個月前檢視次數 64 次
沒有答案

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。

回答問題指南