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

Having trouble getting data to be distinct per user #27

Open
SteveALee opened this issue May 19, 2016 · 6 comments
Open

Having trouble getting data to be distinct per user #27

SteveALee opened this issue May 19, 2016 · 6 comments
Labels

Comments

@SteveALee
Copy link

I'm using UserPools and have followed your example code here but when i have 2 users the data is shared between them. Obviously not what I want! For now I'm not using sync, just logging the users in and out and getting / putting.

  • In the example in the README you say make sure the identity pool should allow unauthenticated access. Surely that is just for the demo code? I do not want unauthenticated access.
  • Shouldn't I use the Identity pool configured to work the the UserPool? If I do that I get 400 Bad request
  • I'm assuming that the sync code pulls the tokens and identity out of the AWS config as no examples so it being shared explicitly
  • I'm always seeing 'null.MyDataSet' in local storage as well as those for the 2 identies
  • Is there some further config I need that I have not discovered yet?

My code is
https://github.com/OpenDirective/brian/blob/master/src/js/drivers/providers/aws/sync-aws-cognito.js
https://github.com/OpenDirective/brian/blob/master/src/js/drivers/providers/aws/sync-aws-cognito.js

thanks

@itrestian
Copy link
Contributor

Hi Steve,

What data are you getting and putting? Are you using sync to do that?

The flow we support is to use User Pools to get an Id Token. Use that Id Token to get an authenticated Identity with Cognito Identity. Finally, use that authenticated identity with Sync to synchronize your data.

Ionut.

@SteveALee
Copy link
Author

Thanks. I believe I am doing that but without any complete example I cannot be sure.

So I use the pools example to log in a user to userpool using a EU identity pool. In the final callback in the login process I create the credentials passing the logins key as shown in some examples I found ( some do it differently)

At this point I see 3 tokens in local storage and another value.

Then I call the set for sync with some data. Actually serialised javascript data, I set 2 different keys. I realise rhis is inefficient but will do for now.

I see extra keys in local storage 2 end with the dataset name. One starts with null and the other some sort of guide.

I then logout out the user and log in anothet. When I get the keys is see th e values from the 1st user whuch is obviously incorrect.

Im not calling sync to server but that can't be required as connectivity might be down

Thanjs

@SteveALee
Copy link
Author

1 point of confusion is how the separate regions passed to the config object interplay with the region embedded in the identity ids. Plus if I need to use the same indents pool for bother cognito userpools and cognito sync.
There are many components here and it's not clear how exactly to get your ducks in a row :)

@SteveALee
Copy link
Author

SteveALee commented May 25, 2016

@itrestian

I'm really stuck with getting a basic set / get to work. Any help will be gratefully received. Thanks

I'm following these docs
http://docs.aws.amazon.com/cognito/latest/developerguide/synchronizing-data.html

my code is

    AWS.config.region = AWSCONFIG.SyncIdentityRegion
    AWS.config.credentials = new AWS.CognitoIdentityCredentials({
      IdentityPoolId: AWSCONFIG.SyncIdentityPoo
    })
    const client = new AWS.CognitoSyncManager()
    client.openOrCreateDataset('dataset', (err, dataset) => {
      if (err) {
        console.error('Cognito sync error - Dataset', err)
      }
      console.debug('dataset', dataset)

      dataset.put('sss', '123', (err, record) => {
        if (err) {
          console.error('Cognito sync error - Put', err)
          return
        }
        console.debug('Put', record)
      })

      dataset.get('sss', (err, value) => {
        if (err) {
          console.error('Cognito sync error - get', err)
          return
        }
        console.debug('Got', value)
      })
    })
  }

I always get undefined back from the get. I can see the data has been put in the local storage. Here's the console output

dataset a {MAX_RETRY: 3, datasetName: "dataset", provider: a.C…s.a.u…l.i…t.constructor, local: a, remote: a}

Put a {key: "sss", value: "123", syncCount: 0, lastModifiedDate: Wed May 25 2016 21:48:34 GMT+0100 (GMT Summer Time), lastModifiedBy: ""…}
deviceLastModifiedDate: Wed May 25 2016 21:48:34 GMT+0100 (GMT Summer Time)
key: "sss"
lastModifiedBy: ""
lastModifiedDate: Wed May 25 2016 21:48:34 GMT+0100 (GMT Summer Time)
modified: true
syncCount: 0
value: "123"

Got undefined

thanks

@SteveALee
Copy link
Author

It seems strange that 'modifiedBy is "" I have set the the tokens via cognito. I have enable unauthenticated access in the identity pool. but also given my User Pool Details in case that is need. The pool log only shows unautheticated access.

    const authenticationDetails = new AWSCognito.CognitoIdentityServiceProvider.AuthenticationDetails(authenticationData)
    cognitoUser.authenticateUser(authenticationDetails, {
      onSuccess: () => {
        cognitoUser.getSession((err, result) => {
          if (!err && result) {
            // Add the User's Id Token to the Cognito credentials login map.
            let credentials = {
              IdentityPoolId: AWSCONFIG.IdentityPoolId,
              Logins: {}  // updated below
            }
            credentials.Logins[AWSCONFIG.loginCredentials] = result.getIdToken().getJwtToken()
            AWS.config.credentials = new AWS.CognitoIdentityCredentials(credentials)
          }
        })
      },

@RWOverdijk
Copy link

👍 examples would be cool. I think it's a shame that it took six months to add a label, and that now, four months later, there's still no resolution.

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

No branches or pull requests

3 participants