{"action":"created","issue":{"url":"https://api.github.com/repos/aws-amplify/amplify-js/issues/1353","repository_url":"https://api.github.com/repos/aws-amplify/amplify-js","labels_url":"https://api.github.com/repos/aws-amplify/amplify-js/issues/1353/labels{/name}","comments_url":"https://api.github.com/repos/aws-amplify/amplify-js/issues/1353/comments","events_url":"https://api.github.com/repos/aws-amplify/amplify-js/issues/1353/events","html_url":"https://github.com/aws-amplify/amplify-js/issues/1353","id":346306809,"node_id":"MDU6SXNzdWUzNDYzMDY4MDk=","number":1353,"title":"getUserData depends on getSession, usage is invalid","user":{"login":"andrew-aladev","id":941925,"node_id":"MDQ6VXNlcjk0MTkyNQ==","avatar_url":"https://avatars3.githubusercontent.com/u/941925?v=4","gravatar_id":"","url":"https://api.github.com/users/andrew-aladev","html_url":"https://github.com/andrew-aladev","followers_url":"https://api.github.com/users/andrew-aladev/followers","following_url":"https://api.github.com/users/andrew-aladev/following{/other_user}","gists_url":"https://api.github.com/users/andrew-aladev/gists{/gist_id}","starred_url":"https://api.github.com/users/andrew-aladev/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/andrew-aladev/subscriptions","organizations_url":"https://api.github.com/users/andrew-aladev/orgs","repos_url":"https://api.github.com/users/andrew-aladev/repos","events_url":"https://api.github.com/users/andrew-aladev/events{/privacy}","received_events_url":"https://api.github.com/users/andrew-aladev/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-07-31T18:28:57Z","updated_at":"2018-07-31T19:56:02Z","closed_at":null,"author_association":"NONE","body":"Hello. I couldn't understand a logic of `currentUserPoolUser` from [packages/auth/src/Auth.ts#L765](https://github.com/aws-amplify/amplify-js/blob/master/packages/auth/src/Auth.ts#L765). Let's try to describe it.\r\n\r\n```\r\n// refresh the session if the session expired.\r\nuser.getSession(...\r\n...\r\n// get user data from Cognito, also to make sure the user is still valid\r\nuser.getUserData(...\r\n....\r\n```\r\n\r\nThese functions are [here](https://github.com/aws-amplify/amplify-js/blob/master/packages/amazon-cognito-identity-js/src/CognitoUser.js#L1118):\r\n\r\n```\r\ngetSession(callback) {\r\nif (this.signInUserSession != null && this.signInUserSession.isValid()) {\r\n  return callback(null, this.signInUserSession);\r\n}\r\n...\r\nthis.refreshSession(refreshToken, callback);\r\n...\r\n```\r\n\r\n```\r\ngetUserData(callback) {\r\nif (!(this.signInUserSession != null && this.signInUserSession.isValid())) {\r\n  return callback(new Error('User is not authenticated'), null);\r\n}\r\n... getting user ...\r\n```\r\n\r\nWhen `this.signInUserSession != null && this.signInUserSession.isValid()` is `false`:\r\n1. `getSession` is refreshing session.\r\n2. `getUserData` throws error.\r\n3. I am sitting here and waiting when cognito will send me a reasonable error about session.\r\n4. I can see that cognito sent me an error: `{\"__type\":\"PasswordResetRequiredException\",\"message\":\"Password reset required for the user\"}`, but promise is already rejected with `User is not authenticated`.\r\n\r\nThere is an obvious fix: call `getUserData` after `await getSession`.\r\n\r\nBut I am not an amazon developer. I shouldn't walk so far away from public api. Both `auth`, `amazon-cognito-identity-js` are **core amplify-js packages** and they are very broken.\r\n\r\nCustomer won't let me waste so much time on level such mountains. Is there any **alternative for amplify-js**?"},"comment":{"url":"https://api.github.com/repos/aws-amplify/amplify-js/issues/comments/409347579","html_url":"https://github.com/aws-amplify/amplify-js/issues/1353#issuecomment-409347579","issue_url":"https://api.github.com/repos/aws-amplify/amplify-js/issues/1353","id":409347579,"node_id":"MDEyOklzc3VlQ29tbWVudDQwOTM0NzU3OQ==","user":{"login":"andrew-aladev","id":941925,"node_id":"MDQ6VXNlcjk0MTkyNQ==","avatar_url":"https://avatars3.githubusercontent.com/u/941925?v=4","gravatar_id":"","url":"https://api.github.com/users/andrew-aladev","html_url":"https://github.com/andrew-aladev","followers_url":"https://api.github.com/users/andrew-aladev/followers","following_url":"https://api.github.com/users/andrew-aladev/following{/other_user}","gists_url":"https://api.github.com/users/andrew-aladev/gists{/gist_id}","starred_url":"https://api.github.com/users/andrew-aladev/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/andrew-aladev/subscriptions","organizations_url":"https://api.github.com/users/andrew-aladev/orgs","repos_url":"https://api.github.com/users/andrew-aladev/repos","events_url":"https://api.github.com/users/andrew-aladev/events{/privacy}","received_events_url":"https://api.github.com/users/andrew-aladev/received_events","type":"User","site_admin":false},"created_at":"2018-07-31T19:56:02Z","updated_at":"2018-07-31T19:56:02Z","author_association":"NONE","body":"We can see `checkUser` function usage for example in [packages/aws-amplify-react/src/Auth/Greetings.jsx](https://github.com/aws-amplify/amplify-js/blob/master/packages/aws-amplify-react/src/Auth/Greetings.jsx#L100). \r\n\r\n```\r\nAuth.currentAuthenticatedUser()\r\n  .catch(err => {\r\n    this.signOut();\r\n  });\r\n```\r\n\r\nThis solution is completely wrong. You are forcing user to sign out + sign in without any reason. This usage should be something like this:\r\n\r\n```\r\nAuth.currentAuthenticatedUser()\r\n  .catch(err => {\r\n    switch (err.code) {\r\n      case 'PasswordResetRequiredException':\r\n        ...\r\n      default:\r\n        this.signOut();\r\n    }\r\n  });\r\n```\r\n\r\nThis code will force you to reproduce the same issue that I've tried to describe here."}}
{"actor":{"display_login":"andrew-aladev"}}