Amplify-js: React-Native: Datastore not syncing/subscribing after signing out and signing in with new user

Created on 12 Mar 2020  路  3Comments  路  Source: aws-amplify/amplify-js

Describe the bug
When I sign in with a new user after using withAuthenticator HOC "Sign Out", DataStore doesn't syncs with the data of the new signed in user and the datastore subscriptions stop working.

After closing and re-opening the application, both the syncing process and the subscriptions start working as expected, and I can see the updated data for the currently signed in user.

To Reproduce
Steps to reproduce the behavior:

  1. Sign In with user A
  2. Both data syncing will retrieve the updated data from the backend and you will receive subscription events related to insertions of objects that belong to the currently signed in user.
  3. Sign out
  4. Sign in with user B
  5. Data for user B is not synced and the user doesn't receive any subscription events for create/update mutations triggered from the backend.
  6. Sign out
  7. Close and re-open the application
  8. Sign in with user B
  9. Both data syncing will retrieve the updated data from the backend and you will receive subscription events related to insertions of objects that belong to the currently signed in user.

Link to sample code

app.js: https://gist.github.com/megasolis/1bfcdaabbda068c59068d7f9cfb5f3b9
schema.graphql: https://gist.github.com/megasolis/2b1b3e8a5eed0813d26c53e3f8cd6661

Expected behavior
Data of user B should be synced and subscriptions should work after signing-in even if app is not closed and re-opened.


Environment

  npmPackages:
    @aws-amplify/core: ^2.2.5 => 2.2.5 
    @aws-amplify/datastore: ^1.0.8 => 1.0.8 
    @babel/core: ^7.6.2 => 7.8.7 
    @babel/runtime: ^7.6.2 => 7.8.7 
    @react-native-community/eslint-config: ^0.0.5 => 0.0.5 
    @react-native-community/netinfo: ^5.6.2 => 5.6.2 
    amazon-cognito-identity-js: ^3.2.5 => 3.2.5 
    aws-amplify: ^2.2.6 => 2.2.6 
    aws-amplify-react-native: ^3.2.2 => 3.2.2 
    babel-jest: ^24.9.0 => 24.9.0 
    eslint: ^6.5.1 => 6.8.0 
    ini: ^1.3.5 => 1.3.5 
    inquirer: ^6.5.1 => 6.5.2 
    jest: ^24.9.0 => 24.9.0 
    metro-react-native-babel-preset: ^0.56.0 => 0.56.4 
    react: 16.9.0 => 16.9.0 
    react-native: 0.61.5 => 0.61.5 
    react-test-renderer: 16.9.0 => 16.9.0 
  npmGlobalPackages:
    @aws-amplify/cli: 4.13.3
    npm: 6.4.1

Smartphone (please complete the following information):

  • Device: Nokia 6
  • OS: Android 9
DataStore React Native to-be-reproduced

Most helpful comment

As my findings are more on the side of #5076, I commented it there, but the solution is pretty much it.

https://github.com/aws-amplify/amplify-js/issues/5076#issuecomment-598388173

Hope this helps you.

All 3 comments

@megasolis thanks for opening the issue. I'll work on reproducing it.

I came across with this bug before. It seems that DataStore initialized vars/params keep their values even when the subscription is not active (object is initialized and that makes it "unable" to sync with new data as something like a "last sync" property cache keeps its value).

Solution is to use DataStorage.clear() to reset such values, but then this bug takes place #5076, making the class/library unable to use any method anymore until you close and reopen the app because a 'undefined' exception occurs (which then again is not desirable behavior, and seems like something done wrong in their init/start process).

I will check for something quick and then go back here to comment out my findings.

As my findings are more on the side of #5076, I commented it there, but the solution is pretty much it.

https://github.com/aws-amplify/amplify-js/issues/5076#issuecomment-598388173

Hope this helps you.

Was this page helpful?
0 / 5 - 0 ratings