Hey everyone, I have a query to verify an user in ...
# help
h
Hey everyone, I have a query to verify an user in aws cognito. Like if a user (signed via fb/google) already exists then redirect them to login. I have used the following function for that.
const existingUser = await cognito.send(
new AdminGetUserCommand({
UserPoolId: config.cognito.USER_POOL_ID,
Username: user.email,
})
); if (exisitingUser) {}
But seems like it doesn't work. Can someone please help me with this?
f
Hey @heyysaiii, can you provide more details on what is not working? (ie. is it not redirecting or is it not recognizing the user email already exist?)
h
It's showing an error “Credential is missing”
g
@heyysaiii the AdminGetUserCommand requires "Calling this action requires developer credentials." If this is inside a lambda function then you need permissions for Cognito pool + admin permissions. if this is in the frontend then it's not recommended to use admin actions in the frontend. (since your use case is intended for all users and not just admins)
h
@Gabriel thanks for the update, the main issue is to verify an user in cognito if the email id exists or not. If the email Id exists then user has to sign in else sign up. How can I implement it then??
g
@heyysaiii can you be more specific about your flow? Is this your frontend application? If you are using federated login (via google/fb) why do you need to check if a user exists? Federated login will either: 1. automatically create a user in the User Pool after login. 2. Or if the user exists it will login the user into the application. see here: https://docs.amplify.aws/lib/auth/social/q/platform/js/