I set up authorization and login in the Cognito via Google. Now I need to get to the user attributes, but I don't understand how can I do it? Existing apis like getSession don't work,and throwing an error.
I use React and library 'amazon-cognito-identity-js'.
I loggin via Google this way:
const path = `https://${myDomain}.auth.us-east-1.amazoncognito.com/login?response_type=code&client_id=${clientId}&redirect_uri=${redirect}`;
router.push(path);
My email appears in User Pool - that's OK.
After successful redirect I call this code, because I need a session to get the user attributes:
const getSession = (role: TRoles): Promise<IReturnObj> => {
return new Promise((resolve, reject) => {
const user = MyPool.getCurrentUser();
if (!user) {
reject(new Error('Current user not found'));
}
user.getSession((err: Error, session: CognitoUserSession) => {
if (err) {
reject(err);
} else {
resolve({session, user});
}
});
});
};
In result I get undefined user and reject error. What I doing wrong?