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:
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!
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.