Open joe455 opened 6 years ago
Hi @joe455, are you calling getCurrentUser() in your onSuccess() callback?
Nope. I didn't understood this one yet I guess. I will walk through with my steps. I am developing this app in angular4.
Could you please let me what I did wrong here?
@joe455 As you described, you try to call getCurrentUser() once you signed in successfully and are redirected to the myprofile page, which is correct. I am not entirely sure why it gives the null.
So basically it should give me the current user details as a cognito user on the redirected page. Isn't correct?
@yuntuowang auth.signOut() is not logging out the facebook.
"So basically it should give me the current user details as a cognito user on the redirected page. Isn't correct?" @joe455 Yes, you are correct.
OMG..Then why it's giving me null..I will look into this.
Hi @joe455, I think the reason you getting null is cause of a known bug from us. Currently the signed in user is not updated correctly. Basically when caching tokens and scopes, the username should be updated to username getting from id token. We will push this bug fix really soon. Will post on this issue once we pushed, thanks!
Hi @joe455, our bug fix has been pushed! Please use version v1.1.1, you can download directly from github or use npm to install the latest version. Thanks!!
Hello @joe455 or @yuntuowang, how can I call getCurrentUser() with the Cognito Auth API? It seems to be part of the Cognito Identity API and I am not sure if both APIs can coexist.
I can use the hosted UI and login, however in the onSuccess handler, I need to obtain information about the current user. I am using Cognito User Pool with Implict Grant flow. In the onSuccess handler I have access to the session and CognitoAuth objects.
Hi @kawsark, you need to call getCurrentUser() method(which is defined in this SDK, Line 151 in CognitoAuth.js file), it is not the Cognito Identity API, has nothing to do with the Cognito Identity service. It may be confusing since they have the same name.
So in your onSuccess handler, you need to call this getCurrentUser() method and get the info about the current signed in user.
Thanks a lot! Let me know if you have any other questions.
@yuntuowang I was calling getCurrentUser() method on identity JS SDK till now. Thanks for clarifying this. I will give a try on this.
Hi @joe455, sorry for the confusion. Basically we need to use accurate wording. The Auth SDK only provides two APIs, getSession() and signOut().
You can also use all the other methods defined in the SDK, e.g. getCurrentUser() method. All of these methods has nothing to do with other SDKs.
Thank you @yuntuowang , I was able to retrieve the username using getCurrentUser(). To retrieve some of the attributes specified during signup (email, Name etc.), I assume the Cognito Identity SDK is needed? The cognitoUser.getUserAttributes() function doesn't seem to exist in this API. Let me know if there is a different way to retrieve the attributes. I can't import both amazon-cognito-auth.js and amazon-cognito-identity.js in the same .js file.
Hi @kawsark, yes, getCurrentUser() only gives you the current signed in user's username.
Here is a great example about how to use Cognito User Pools and Cognito Identity with this SDK and the Cognito ID SDK in a vanilla create-react-app: https://gist.github.com/gabeweaver/d1be9f0d41069437f576c375c30e134c
Hi @kawsark, to retrieve some of the attributes specified during signup (email, Name etc.), you can parse the id_token returned by cognito once you signed in (you have set the 'openid' as a scope, or you set nothing for scope('openid' is the default setting)).
I am able to save the facebook user into userpool but when I am trying to retrive the current user on the redirected page, it's giving null always.Can somebody tell me why this is happening?