Skip to content
This repository has been archived by the owner on Sep 16, 2020. It is now read-only.

Sync unauthenticated user data with just authenticated user #59

Open
pmbanugo opened this issue Feb 9, 2018 · 1 comment
Open

Sync unauthenticated user data with just authenticated user #59

pmbanugo opened this issue Feb 9, 2018 · 1 comment

Comments

@pmbanugo
Copy link

pmbanugo commented Feb 9, 2018

My app allows user add data while unauthenticated with cognito sync. I want a situation where when a user logs in, it takes data it saved while user was unauthenticated and merges it with the data owned by the just authenticated user. How do I achieve this?

@abuist
Copy link

abuist commented Mar 5, 2018

I had this issue last year and found that it is actually a Cognito Identity issue. When you call the AWS.CognitoIdentityCredentials with the new user authenticated user it allocated you a new IdentityId.

So I retrieve the previously stored IdentityId from localStorage using hwIdentity = AWS.config.credentials.identityId; before I start the authentication process.

Then when I I retrieve the new credentials I pass it it as part of the parameters as follows:
AWS.config.credentials = new AWS.CognitoIdentityCredentials({
'IdentityPoolId': aws_cognito_identity_pool_id,
'IdentityId': hwIdentity,
'Logins': logins
});

This causes CognitoIdentity to add the new user information to the Identity or merge Identities if their are 2, which will initiate the Cognito Sync merge process.

Hope this Helps.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants