payload: {"action":"created","issue":{"url":"https://api.github.com/repos/aws-amplify/amplify-js/issues/3033","repository_url":"https://api.github.com/repos/aws-amplify/amplify-js","labels_url":"https://api.github.com/repos/aws-amplify/amplify-js/issues/3033/labels{/name}","comments_url":"https://api.github.com/repos/aws-amplify/amplify-js/issues/3033/comments","events_url":"https://api.github.com/repos/aws-amplify/amplify-js/issues/3033/events","html_url":"https://github.com/aws-amplify/amplify-js/issues/3033","id":430049498,"node_id":"MDU6SXNzdWU0MzAwNDk0OTg=","number":3033,"title":"Using Facebook Login, why does Amplify (using Auth.currentAuthenticatedUser()) not work immediately after login, but if I refresh the app (Command + R in the iOS simulator), the user is recognized?","user":{"login":"cmaronchick","id":11731784,"node_id":"MDQ6VXNlcjExNzMxNzg0","avatar_url":"https://avatars2.githubusercontent.com/u/11731784?v=4","gravatar_id":"","url":"https://api.github.com/users/cmaronchick","html_url":"https://github.com/cmaronchick","followers_url":"https://api.github.com/users/cmaronchick/followers","following_url":"https://api.github.com/users/cmaronchick/following{/other_user}","gists_url":"https://api.github.com/users/cmaronchick/gists{/gist_id}","starred_url":"https://api.github.com/users/cmaronchick/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cmaronchick/subscriptions","organizations_url":"https://api.github.com/users/cmaronchick/orgs","repos_url":"https://api.github.com/users/cmaronchick/repos","events_url":"https://api.github.com/users/cmaronchick/events{/privacy}","received_events_url":"https://api.github.com/users/cmaronchick/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2019-04-06T16:13:16Z","updated_at":"2019-04-09T18:35:25Z","closed_at":null,"author_association":"NONE","body":"** Which Category is your question related to? **\r\nAmplify Facebook Login Integration\r\n\r\n** What AWS Services are you utilizing? **\r\nAmplify, Auth\r\n\r\n** Provide additional details e.g. code snippets **\r\n\r\n          const details = {\r\n            grant_type: 'authorization_code',\r\n            code,\r\n            client_id: userPool.clientId,\r\n            redirect_uri: AuthSession.getRedirectUrl()\r\n          }\r\n          const formBody = Object.keys(details)\r\n            .map(\r\n              key => `${encodeURIComponent(key)}=${encodeURIComponent(details[key])}`\r\n            )\r\n            .join(\"&\");\r\n  \r\n         try {\r\n            let res = await fetch(\r\n            'https://crowdsourcedscores.auth.us-west-2.amazoncognito.com/oauth2/token',\r\n              {\r\n                method: \"POST\",\r\n                headers: {\r\n                  'Content-type': 'application/x-www-form-urlencoded;charset=UTF-8'\r\n                },\r\n                body: formBody\r\n              }\r\n            )\r\n            let tokenRequestJson = await res.json();\r\n            const IdToken = new CognitoIdToken({ IdToken: tokenRequestJson.id_token });\r\n            const AccessToken = new CognitoAccessToken({ AccessToken: tokenRequestJson.access_token });\r\n            const RefreshToken = new CognitoRefreshToken({ RefreshToken: tokenRequestJson.refresh_token })\r\n              try {\r\n                let userSession = new CognitoUserSession({ IdToken, AccessToken, RefreshToken });\r\n                \r\n                const userData = {\r\n                  Username: IdToken.payload['cognito:username'],\r\n                  Pool: userPool\r\n                };\r\n                let authUser = Auth.createCognitoUser(userData);\r\n                let authSession = await Auth.userSession(authUser)\r\n                let authCurrentUser = Auth.currentAuthenticatedUser() <!--- RETURNS NULL; WHY? -->\r\n              } catch (userError) {\r\n             //HANDLE USERERROR\r\n              }\r\n          } catch (fetchError) {\r\n             //HANDLE FETCHERROR\r\n          }"},"comment":{"url":"https://api.github.com/repos/aws-amplify/amplify-js/issues/comments/481377675","html_url":"https://github.com/aws-amplify/amplify-js/issues/3033#issuecomment-481377675","issue_url":"https://api.github.com/repos/aws-amplify/amplify-js/issues/3033","id":481377675,"node_id":"MDEyOklzc3VlQ29tbWVudDQ4MTM3NzY3NQ==","user":{"login":"powerful23","id":11042868,"node_id":"MDQ6VXNlcjExMDQyODY4","avatar_url":"https://avatars1.githubusercontent.com/u/11042868?v=4","gravatar_id":"","url":"https://api.github.com/users/powerful23","html_url":"https://github.com/powerful23","followers_url":"https://api.github.com/users/powerful23/followers","following_url":"https://api.github.com/users/powerful23/following{/other_user}","gists_url":"https://api.github.com/users/powerful23/gists{/gist_id}","starred_url":"https://api.github.com/users/powerful23/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/powerful23/subscriptions","organizations_url":"https://api.github.com/users/powerful23/orgs","repos_url":"https://api.github.com/users/powerful23/repos","events_url":"https://api.github.com/users/powerful23/events{/privacy}","received_events_url":"https://api.github.com/users/powerful23/received_events","type":"User","site_admin":false},"created_at":"2019-04-09T18:35:25Z","updated_at":"2019-04-09T18:35:25Z","author_association":"CONTRIBUTOR","body":"@cmaronchick can you try this:\r\n```js\r\ntry {\r\n            let userSession = new CognitoUserSession({ IdToken, AccessToken, RefreshToken });\r\n            \r\n            const userData = {\r\n              Username: IdToken.payload['cognito:username'],\r\n              Pool: userPool\r\n            };\r\n            let authUser = Auth.createCognitoUser(userData);\r\n\r\n            authUser.setSession(userSession);\r\n\r\n            let authSession = await Auth.userSession(authUser)\r\n            let authCurrentUser = Auth.currentAuthenticatedUser();\r\n } catch (userError) {\r\n         //HANDLE USERERROR\r\n        }\r\n```\r\n\r\nBy the way, the way you are using Amplify is kind of hacky and thus not recommended. Could you take a look at this about how to do federation in React-native?: https://aws-amplify.github.io/docs/js/authentication#oauth-and-federation-overview"}}
other: {"actor":{"display_login":"powerful23"}}