Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

React-Native: signing out, clearing DataStore and creating new user throws errors when trying query DataStore #5076

Closed
nylki opened this issue Mar 12, 2020 · 3 comments
Labels
DataStore Related to DataStore category React Native React Native related issue to-be-reproduced Used in order for Amplify to reproduce said issue

Comments

@nylki
Copy link

nylki commented Mar 12, 2020

Describe the bug
When Auth.signOut() is called by a subsequent DataStore.clear(), Auth.signUp() and Auth.signIn() of that newly signed up user, results in errors when trying to query the DataStore for items that should be accessible by everybody:

 WARN  Possible Unhandled Promise Rejection (id: 0):
TypeError: undefined is not an object (evaluating 'storage.query')
http://192.168.127.115:8081/index.bundle?platform=ios&dev=true&minify=false:132391:31
[...snip]

When closing and re-opening the app, I can succesfully query the items that errored out previously.

To Reproduce
My App.js and schema.graphql: https://gist.github.com/nylki/fca10b04e215e777d5506d562f12c340
Users are configured to be able to signup with just username + password and are auto-confirmed in a pre-signup lampda-function.

Expected behavior
When signin out, calling DataStore.clear() and creating a new user, publicly accessible items in the synced DataStore should be resynced after signin or when querying.

Smartphone (please complete the following information):

  • Device: iPhone X
  • OS: iOS 13.2.3
  • React-Native-App

my package.json:

"dependencies": {
        "@aws-amplify/core": "^2.2.5",
        "@aws-amplify/datastore": "^1.0.8",
        "@react-native-community/netinfo": "^5.5.1",
        "amazon-cognito-identity-js": "^3.2.5",
        "aws-amplify": "^2.2.6",
        "aws-amplify-react-native": "^3.2.2",
        "react": "^16.13.0",
        "react-native": "^0.61.5",
        "react-spring": "^8.0.27"
    },
    "devDependencies": {
        "@babel/core": "^7.6.2",
        "@babel/runtime": "^7.6.2",
        "@react-native-community/eslint-config": "^0.0.5",
        "babel-jest": "^24.9.0",
        "eslint": "^6.5.1",
        "eslint-config-standard": "^14.1.0",
        "eslint-plugin-import": "^2.20.1",
        "eslint-plugin-node": "^11.0.0",
        "eslint-plugin-promise": "^4.2.1",
        "eslint-plugin-react": "^7.19.0",
        "eslint-plugin-standard": "^4.0.1",
        "ini": "^1.3.5",
        "inquirer": "^6.5.1",
        "jest": "^24.9.0",
        "metro-react-native-babel-preset": "^0.56.0",
        "react-test-renderer": "16.9.0"
    },
@nylki nylki added the to-be-reproduced Used in order for Amplify to reproduce said issue label Mar 12, 2020
@sammartinez sammartinez added React Native React Native related issue DataStore Related to DataStore category labels Mar 12, 2020
@yirako
Copy link
Contributor

yirako commented Mar 12, 2020

It seems that DataStorage.clear() sets storage object to undefined and it doesn't get reconstructed on next calls.

Image

image

Looking at DataStorage source this is correct.

Image

image

Now looking at the internal start() function, looks like as initialized already has a value after using clear(), it falls into the else statement and doesn't set the storage var again

Image

image

Solution might be to also set initialized to undefined on clear()

@nylki nylki changed the title React-Native: signing out and creating new user throws errors when trying query DataStore React-Native: signing out, clearing DataStore and creating new user throws errors when trying query DataStore Mar 12, 2020
yirako added a commit to yirako/amplify-js that referenced this issue Mar 12, 2020
@nylki
Copy link
Author

nylki commented Mar 18, 2020

super, thanks!

jordanranz added a commit that referenced this issue Mar 27, 2020
* Adding database abstraction for AsyncStorage

* Add storage adapter for React Native using AsyncStorage

* Add separate default adapters for Web and React Native

* Make error messages more meaningful

* Add support for Reachability in React Native

* Add @react-native-community/netinfo to devDependencies

* Pin down the version of crypto-js

* Enable publish from rn-datastore branch

* Preparing release

* chore(release): Publish [ci skip]

 - @aws-amplify/analytics@2.2.5
 - aws-amplify-angular@4.1.6
 - aws-amplify-react@3.1.6
 - aws-amplify@2.2.5
 - @aws-amplify/datastore@1.0.7
 - @aws-amplify/pubsub@2.1.6

* Allow in PubSub to add async custom headers

Allow in PubSub the same capabilities as API for custom headers:
* Async header
* Override headers (Authorization)

Check issue #4928 for explanations.

* chore(deps-dev): bump codecov from 1.0.1 to 3.6.5 (#4951)

Bumps [codecov](https://github.com/codecov/codecov-node) from 1.0.1 to 3.6.5.
- [Release notes](https://github.com/codecov/codecov-node/releases)
- [Commits](https://github.com/codecov/codecov-node/commits)

Signed-off-by: dependabot[bot] <support@github.com>

* (fix:@aws-amplify/pubsub) Fix for unsubscription new subscription race condition (#4956)

* Fix for unsubscription new subscription race condition

* Update packages/pubsub/src/Providers/AWSAppSyncRealTimeProvider.ts

* Fix to initialize only once and handle disconnection from network  (#4921)

* initialize only once

* Fix onerror handler for WebSocket

* Change log level for unsubscribe message

* Add regions and fix typo

* Handle disconnection

* chore(deps): bump nokogiri from 1.10.4 to 1.10.8 in /docs (#4974)

Bumps [nokogiri](https://github.com/sparklemotion/nokogiri) from 1.10.4 to 1.10.8.
- [Release notes](https://github.com/sparklemotion/nokogiri/releases)
- [Changelog](https://github.com/sparklemotion/nokogiri/blob/master/CHANGELOG.md)
- [Commits](sparklemotion/nokogiri@v1.10.4...v1.10.8)

Signed-off-by: dependabot[bot] <support@github.com>

* Use the db instance property of the Adapter class for all database operations (#4995)

Use the db instance property of the Adapter class for all database operations

* Removing unused code

* Remove rn-datastore branch publish config

* Preparing release

* chore(release): Publish [ci skip]

 - amazon-cognito-identity-js@3.2.5
 - @aws-amplify/analytics@2.2.6
 - @aws-amplify/api@2.1.6
 - @aws-amplify/auth@2.1.6
 - aws-amplify-angular@4.1.7
 - aws-amplify-react@3.1.7
 - aws-amplify@2.2.6
 - @aws-amplify/cache@2.1.6
 - @aws-amplify/core@2.2.5
 - @aws-amplify/datastore@1.0.8
 - @aws-amplify/interactions@2.1.6
 - @aws-amplify/predictions@2.1.6
 - @aws-amplify/pubsub@2.1.7
 - @aws-amplify/pushnotification@2.1.6
 - @aws-amplify/storage@2.2.1
 - @aws-amplify/xr@1.1.6

* fix(core): move react-native dependency from dev

* fix(core): revert dep addition. Add to peer and devDeps

* ci: Add React Native integration testing with Detox (#5007)

* Make deploy wait on integ_rn_ios_storage (#5009)

* feat(@aws-amplify/api): pass additionalHeaders to graphql function (#5001)

Additional headers are merged **after** merging in headers set at config time.
Additional headers will overwrite any existing values and merge the rest.

* chore(@aws-amplify/api): fix non-breaking typo in function (#5034)

* fix(@aws-amplify/datastore): Fix query and delete types (#5032)

Fixes #4827

* Fix(@aws-amplify/interactions) fixes 4750 to properly use the spread operator (#4806)

* fix(@aws-amplify/datastore) Adding socket disconnection detection (#5086)

* Export necessary providers and types from the package root to avoid importing from generated paths (#5085)

* fix(aws-amplify-react): Fix Federated icons when using React Bo… (#5073)

* Explicitly set box-sizing, as CSS resets override to border-box

* Explicitly set line-height, as CSS resets override line-height

* Upgrade aws-sdk clients which resolves react native issues (#5124)

* Export necessary providers and types from the package root to avoid importing from generated paths

* Upgrade aws-sdk clients which resolves react native issues

* Enable integration tests on modularization branch (#5125)

* chore: Fix setup-dev script (#5035)

Let `unlink-all` succeed always

Co-authored-by: Iglesias <manuelig@3c22fb19fec4.ant.amazon.com>

* fix(@aws-amplify/datastore): Storage should be re-initialized after DataStore.clear() (#5083)

* fix(@aws-amplify/datastore): Fix #5076 storage not re-initialized after DataStore.clear()

* Adding comments

Co-authored-by: Manuel Iglesias <manuelig@amazon.com>
Co-authored-by: Ashish Nanda <ashish.nanda.5591@gmail.com>

* fix(aws-amplify-react): BREAKING - Remove "import '@aws-amplify… (#5138)

Importing non-JS files relies on a bundler & breaks SSR.

It works with CRA because CRA *builds all dependencies*, just-in-case.

* feat(@aws-amplify/datastore): Support non-@model types in DataStore (#5128)

* Upgrade immer

* Return sooner if predicates are empty

* Fix bug when trying to delete a model instance that is not persisted

* Support non-@model types

* Generate datastore coverage report and RN integ test

* Fix tslint error

* Remove  unit test case for onGetPost

* Remove unused code

* Rename instance initializer to initializeInstance

* Rename SchemaType to SchemaNonModel

* Rename types to nonModels in schema.js

* Rename type to nonModel

* Make nonModels optional in schema.js

* Remove generic constraint from createTypeClass

* Rename ModelOrTypeConstructorMap to TypeConstructorMap

* Rename createModelAndTypeClassses to createTypeClasses

* Rename createTypeClass to createNonModelClass

* chore: remove datastore form RN integ tests (#5139)

* Fix export type of datastore storage in unit tests

* test(@aws-amplify/datastore): Fix unit tests

* [RN] Migrate zen-observable to zen-observable-ts and fix zen-push import (#5155)

* Migrate zen-observable to zen-observable-ts and fix zen-push import

* Fix unit tests

* Pin aws-sdk versions and rename presignRequest to presign (#5171)

* Migrate zen-observable to zen-observable-ts and fix zen-push import

* Fix unit tests

* Pin aws-sdk versions and rename presignRequest to presign

* Upgrade aws-sdk clients from alpha to beta (#5209)

* Migrate zen-observable to zen-observable-ts and fix zen-push import

* Fix unit tests

* Pin aws-sdk versions and rename presignRequest to presign

* Upgrade aws-sdk clients from alpha to beta

* Update expiration type to Date as per change in aws-sdk

* Fix unit tests as per expiration type change

* Fix jest failures, update snapshot

* Update storage changelog

Co-authored-by: Ashish Nanda <ashish.nanda.5591@gmail.com>
Co-authored-by: Rodriguez Elorza <elorzafe@amazon.com>
Co-authored-by: aws-amplify-bot <aws@amazon.com>
Co-authored-by: Sebastien Schwartz <schwartz.seb@gmail.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Manuel Iglesias <manuelig@amazon.com>
Co-authored-by: Ivan Artemiev <29709626+iartemiev@users.noreply.github.com>
Co-authored-by: Jens Bodal <jensbodal@gmail.com>
Co-authored-by: Ashika <35131273+ashika01@users.noreply.github.com>
Co-authored-by: Manuel Iglesias <6154160+manueliglesias@users.noreply.github.com>
Co-authored-by: Praveen Gupta <51211245+Amplifiyer@users.noreply.github.com>
Co-authored-by: Eric Clemmons <eric@smarterspam.com>
Co-authored-by: Iglesias <manuelig@3c22fb19fec4.ant.amazon.com>
Co-authored-by: Yirako <yirako@users.noreply.github.com>
Co-authored-by: pravgupt@amazon.com <pravgupt@8c85905cd208.ant.amazon.com>
@github-actions
Copy link

This issue has been automatically locked since there hasn't been any recent activity after it was closed. Please open a new issue for related bugs.

Looking for a help forum? We recommend joining the Amplify Community Discord server *-help channels or Discussions for those types of questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 12, 2021
CongNguyen086 pushed a commit to CongNguyen086/amplify-js that referenced this issue Oct 5, 2022
* Adding database abstraction for AsyncStorage

* Add storage adapter for React Native using AsyncStorage

* Add separate default adapters for Web and React Native

* Make error messages more meaningful

* Add support for Reachability in React Native

* Add @react-native-community/netinfo to devDependencies

* Pin down the version of crypto-js

* Enable publish from rn-datastore branch

* Preparing release

* chore(release): Publish [ci skip]

 - @aws-amplify/analytics@2.2.5
 - aws-amplify-angular@4.1.6
 - aws-amplify-react@3.1.6
 - aws-amplify@2.2.5
 - @aws-amplify/datastore@1.0.7
 - @aws-amplify/pubsub@2.1.6

* Allow in PubSub to add async custom headers

Allow in PubSub the same capabilities as API for custom headers:
* Async header
* Override headers (Authorization)

Check issue aws-amplify#4928 for explanations.

* chore(deps-dev): bump codecov from 1.0.1 to 3.6.5 (aws-amplify#4951)

Bumps [codecov](https://github.com/codecov/codecov-node) from 1.0.1 to 3.6.5.
- [Release notes](https://github.com/codecov/codecov-node/releases)
- [Commits](https://github.com/codecov/codecov-node/commits)

Signed-off-by: dependabot[bot] <support@github.com>

* (fix:@aws-amplify/pubsub) Fix for unsubscription new subscription race condition (aws-amplify#4956)

* Fix for unsubscription new subscription race condition

* Update packages/pubsub/src/Providers/AWSAppSyncRealTimeProvider.ts

* Fix to initialize only once and handle disconnection from network  (aws-amplify#4921)

* initialize only once

* Fix onerror handler for WebSocket

* Change log level for unsubscribe message

* Add regions and fix typo

* Handle disconnection

* chore(deps): bump nokogiri from 1.10.4 to 1.10.8 in /docs (aws-amplify#4974)

Bumps [nokogiri](https://github.com/sparklemotion/nokogiri) from 1.10.4 to 1.10.8.
- [Release notes](https://github.com/sparklemotion/nokogiri/releases)
- [Changelog](https://github.com/sparklemotion/nokogiri/blob/master/CHANGELOG.md)
- [Commits](sparklemotion/nokogiri@v1.10.4...v1.10.8)

Signed-off-by: dependabot[bot] <support@github.com>

* Use the db instance property of the Adapter class for all database operations (aws-amplify#4995)

Use the db instance property of the Adapter class for all database operations

* Removing unused code

* Remove rn-datastore branch publish config

* Preparing release

* chore(release): Publish [ci skip]

 - amazon-cognito-identity-js@3.2.5
 - @aws-amplify/analytics@2.2.6
 - @aws-amplify/api@2.1.6
 - @aws-amplify/auth@2.1.6
 - aws-amplify-angular@4.1.7
 - aws-amplify-react@3.1.7
 - aws-amplify@2.2.6
 - @aws-amplify/cache@2.1.6
 - @aws-amplify/core@2.2.5
 - @aws-amplify/datastore@1.0.8
 - @aws-amplify/interactions@2.1.6
 - @aws-amplify/predictions@2.1.6
 - @aws-amplify/pubsub@2.1.7
 - @aws-amplify/pushnotification@2.1.6
 - @aws-amplify/storage@2.2.1
 - @aws-amplify/xr@1.1.6

* fix(core): move react-native dependency from dev

* fix(core): revert dep addition. Add to peer and devDeps

* ci: Add React Native integration testing with Detox (aws-amplify#5007)

* Make deploy wait on integ_rn_ios_storage (aws-amplify#5009)

* feat(@aws-amplify/api): pass additionalHeaders to graphql function (aws-amplify#5001)

Additional headers are merged **after** merging in headers set at config time.
Additional headers will overwrite any existing values and merge the rest.

* chore(@aws-amplify/api): fix non-breaking typo in function (aws-amplify#5034)

* fix(@aws-amplify/datastore): Fix query and delete types (aws-amplify#5032)

Fixes aws-amplify#4827

* Fix(@aws-amplify/interactions) fixes 4750 to properly use the spread operator (aws-amplify#4806)

* fix(@aws-amplify/datastore) Adding socket disconnection detection (aws-amplify#5086)

* Export necessary providers and types from the package root to avoid importing from generated paths (aws-amplify#5085)

* fix(aws-amplify-react): Fix Federated icons when using React Bo… (aws-amplify#5073)

* Explicitly set box-sizing, as CSS resets override to border-box

* Explicitly set line-height, as CSS resets override line-height

* Upgrade aws-sdk clients which resolves react native issues (aws-amplify#5124)

* Export necessary providers and types from the package root to avoid importing from generated paths

* Upgrade aws-sdk clients which resolves react native issues

* Enable integration tests on modularization branch (aws-amplify#5125)

* chore: Fix setup-dev script (aws-amplify#5035)

Let `unlink-all` succeed always

Co-authored-by: Iglesias <manuelig@3c22fb19fec4.ant.amazon.com>

* fix(@aws-amplify/datastore): Storage should be re-initialized after DataStore.clear() (aws-amplify#5083)

* fix(@aws-amplify/datastore): Fix aws-amplify#5076 storage not re-initialized after DataStore.clear()

* Adding comments

Co-authored-by: Manuel Iglesias <manuelig@amazon.com>
Co-authored-by: Ashish Nanda <ashish.nanda.5591@gmail.com>

* fix(aws-amplify-react): BREAKING - Remove "import '@aws-amplify… (aws-amplify#5138)

Importing non-JS files relies on a bundler & breaks SSR.

It works with CRA because CRA *builds all dependencies*, just-in-case.

* feat(@aws-amplify/datastore): Support non-@model types in DataStore (aws-amplify#5128)

* Upgrade immer

* Return sooner if predicates are empty

* Fix bug when trying to delete a model instance that is not persisted

* Support non-@model types

* Generate datastore coverage report and RN integ test

* Fix tslint error

* Remove  unit test case for onGetPost

* Remove unused code

* Rename instance initializer to initializeInstance

* Rename SchemaType to SchemaNonModel

* Rename types to nonModels in schema.js

* Rename type to nonModel

* Make nonModels optional in schema.js

* Remove generic constraint from createTypeClass

* Rename ModelOrTypeConstructorMap to TypeConstructorMap

* Rename createModelAndTypeClassses to createTypeClasses

* Rename createTypeClass to createNonModelClass

* chore: remove datastore form RN integ tests (aws-amplify#5139)

* Fix export type of datastore storage in unit tests

* test(@aws-amplify/datastore): Fix unit tests

* [RN] Migrate zen-observable to zen-observable-ts and fix zen-push import (aws-amplify#5155)

* Migrate zen-observable to zen-observable-ts and fix zen-push import

* Fix unit tests

* Pin aws-sdk versions and rename presignRequest to presign (aws-amplify#5171)

* Migrate zen-observable to zen-observable-ts and fix zen-push import

* Fix unit tests

* Pin aws-sdk versions and rename presignRequest to presign

* Upgrade aws-sdk clients from alpha to beta (aws-amplify#5209)

* Migrate zen-observable to zen-observable-ts and fix zen-push import

* Fix unit tests

* Pin aws-sdk versions and rename presignRequest to presign

* Upgrade aws-sdk clients from alpha to beta

* Update expiration type to Date as per change in aws-sdk

* Fix unit tests as per expiration type change

* Fix jest failures, update snapshot

* Update storage changelog

Co-authored-by: Ashish Nanda <ashish.nanda.5591@gmail.com>
Co-authored-by: Rodriguez Elorza <elorzafe@amazon.com>
Co-authored-by: aws-amplify-bot <aws@amazon.com>
Co-authored-by: Sebastien Schwartz <schwartz.seb@gmail.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Manuel Iglesias <manuelig@amazon.com>
Co-authored-by: Ivan Artemiev <29709626+iartemiev@users.noreply.github.com>
Co-authored-by: Jens Bodal <jensbodal@gmail.com>
Co-authored-by: Ashika <35131273+ashika01@users.noreply.github.com>
Co-authored-by: Manuel Iglesias <6154160+manueliglesias@users.noreply.github.com>
Co-authored-by: Praveen Gupta <51211245+Amplifiyer@users.noreply.github.com>
Co-authored-by: Eric Clemmons <eric@smarterspam.com>
Co-authored-by: Iglesias <manuelig@3c22fb19fec4.ant.amazon.com>
Co-authored-by: Yirako <yirako@users.noreply.github.com>
Co-authored-by: pravgupt@amazon.com <pravgupt@8c85905cd208.ant.amazon.com>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
DataStore Related to DataStore category React Native React Native related issue to-be-reproduced Used in order for Amplify to reproduce said issue
Projects
None yet
Development

No branches or pull requests

3 participants