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
gefragt vor einem Monat64 Aufrufe
Keine Antworten

Du bist nicht angemeldet. Anmelden um eine Antwort zu veröffentlichen.

Eine gute Antwort beantwortet die Frage klar, gibt konstruktives Feedback und fördert die berufliche Weiterentwicklung des Fragenstellers.

Richtlinien für die Beantwortung von Fragen