8

I have a React Native mobile app in which I'm using AWS Amplify to work with my Cognito user pool.

I am trying to get the "Created" date of the currently signed in user because I want to show existing users an alert when the app starts, but I don't want new users to get that alert. I plan on using the creation date of the user to know if they should see the alert.

When looking at my user pool in the Cognito service in AWS Console, I see that each user does have a "Created" property:

enter image description here

however, I am unsure how I can access that property from within the app. The only relevant method I could find in the docs was Auth.currentAuthenticatedUser(), but that doesn't seem to include the "Created" timestamp in its response.

I did find a reference to AdminGetUser in the Cognito docs which does include a UserCreateDate property, however I don't want to have admin credentials used within the app itself, so I am looking for an alternative.

Any suggestions would be appreciated!

Saad
  • 49,729
  • 21
  • 73
  • 112
  • 1
    I have thoroughly looked into the documentations. But I have not found a non Admin API Call that gets the same piece of information. Have you considered storing the information in Custom Attributes? The users could get the Custom Attribute's populated data without needing Admin Credentials for the API calls. – Arka Mukherjee Apr 18 '19 at 17:34
  • 1
    It's ridiculous that such a fundamental attribute isn't available to a non-admin call by default. Now i have to manually add it as a custom attribute, or proxy the call thru a server for a single attribute? Just ridiculous – Eric Guan Oct 31 '19 at 20:06

1 Answers1

5

There is a way that you can use the AdminGetUser API without providing direct admin access to the users. Since you are using Amplify, you can publish an API (either REST or GraphQL) that calls a Lambda function. The Lambda function in turn is configured with the required cognito-idp:AdminGetUser privilege for reading the user data and then returning it through the api.

matsev
  • 32,104
  • 16
  • 121
  • 156