Display Cognito user custom attribute in react native app

0

I'm working on a react native app with AWS Amplify. Using fetchUserAttributes() function (from aws-amplify/auth), I get my signed in user info as following :{"custom:category": "particulier", "email": "email@gmail.com", ...} I'm ok manipulating and displaying basic attributes such as email in the app with the following : "const userAttributes = await fetchUserAttributes();" and "userAttributes.email".

However, I don't know how to do it with custom attribute such as "custom:category". I tried to get info with "const {?, email, name, ...} = await fetchUserAttributes();" but, once again, I don't know what to put for category.

I didn't find any information about that in the doc or on any forums.

Thanks in advance !

1개 답변
1
수락된 답변

You can't directly destructure it like you do with built-in attributes because of the colon in its name. Instead, access it using bracket notation. Here’s how you can do it:

const userAttributes = await fetchUserAttributes();
const category = userAttributes["custom:category"];
profile picture
전문가
답변함 2달 전
  • I did it using : "const { tokens, credentials, identityId, userSub } = await fetchAuthSession(); const { idToken, accessToken } = tokens; idToken.payload['custom:category']" but I prefer your way. Thank you !

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

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

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

관련 콘텐츠