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

Prevent synchronization of user data #1829

Closed
MSKoWa opened this issue Jun 28, 2022 · 7 comments
Closed

Prevent synchronization of user data #1829

MSKoWa opened this issue Jun 28, 2022 · 7 comments
Assignees
Labels
datastore Issues related to the DataStore Category pending-community-response Pending response from the issue opener or other community members question A question about the Amplify Flutter libraries

Comments

@MSKoWa
Copy link

MSKoWa commented Jun 28, 2022

Hello there,

I would like to only permit the synchronization of the data stored with DataStore if and only if the user bought premium access to the app.
As you can guess, the user must have some kind of authentication because he or she should be able to buy premium access. I do this using the cognito service granting the user an unique ID which is used during the purchasing process.

Now, I have the problem that as soon as the user logs in, the data is synchronized directly...

Hence, I tried to set the "syncMaxRecords" value to 0 when configuring the DataStore Pluging in the app:

final AmplifyDataStore _dataStorePlugin = AmplifyDataStore(
    modelProvider: ModelProvider.instance,
    syncMaxRecords: 0,
  )

This seems to be fine, although I receive some amplify error when the app "tries" to sync:

GraphQLResponseError<PaginatedList<AnyModel>>: GraphQL service returned a successful response containing errors: 
[Amplify.GraphQLError(message: "1 validation error detected: Value \'0\' at \'limit\' failed to satisfy constraint: Member must 
have value greater than or equal to 1 (Service: DynamoDb, Status Code: 400, Request ID: 
O7BUSBKND7SS315NLCLMC1V9B7VV4KQNSO5AEMVJF66Q9ASUAAJG)", locations: 
Optional([Amplify.GraphQLError.Location(line: 2, column: 3)]), path: 
Optional([Amplify.JSONValue.string("syncDataStoreTankProfiles")]), extensions: Optional(["errorType": 
Amplify.JSONValue.string("DynamoDB:DynamoDbException"), "data": Amplify.JSONValue.null, "errorInfo": 
Amplify.JSONValue.null]))]

Is this the way to go??

Best regards

@ragingsquirrel3 ragingsquirrel3 added datastore Issues related to the DataStore Category question A question about the Amplify Flutter libraries labels Jun 28, 2022
@HuiSF
Copy link
Member

HuiSF commented Jun 28, 2022

This is an interesting use case...

Per the current state, as long as API plugin is add and configured with correct configuration, DataStore will attempt data syncing on each DataStore API calls (e.g. save, delete, query etc.). There is no way to stop it permanently and programmatically.

Your workaround is not working due to DynamoDB limitation, that a Scan operation originated from a sync query requires a range 1 to 1000000.

Something I can think of now is to check user subscription tier, and then initialize and add API plugin based on the check. This requires to kill the App process and restart the App after user subscription tier changes. (your workaround also requires this as Amplify plugins are not re-configurable at runtime at this moment).

Please feel free to file a feature request to stop DataStore sync permanently on demand.

@MSKoWa
Copy link
Author

MSKoWa commented Jun 28, 2022

Alright, restarting the app might be the best solution I guess. Thank you!

... where do I pose the feature request?

@MSKoWa
Copy link
Author

MSKoWa commented Jun 28, 2022

Further, it is written in this Flutter Doc:

https://docs.amplify.aws/lib/datastore/sync/q/platform/flutter/#selectively-syncing-a-subset-of-your-data

that also just subsets of data can be synced by providing certain sync expression when configuring the DataStore plugin. It is also said that these expressions can be re-evaluated at runtime by changing some parameter (in this case it is some threshold rating (int) of a post, changed from "at least 5" to "at least 1") and by calling Amplify.DataStore.stop() and a subsequent Amplify.DataStore.start().

By this, I think I should be able to get what I want....:

  • If the user does not have premium, the sync expressions must be evaluated to something that does not match any data
  • If the user does have premium, the sync expression will be evaluated to sync everything

@HuiSF
Copy link
Member

HuiSF commented Jun 29, 2022

where do I pose the feature request?

You can modify your original post in this issue as a feature request. :)

By this, I think I should be able to get what I want....

I personally not recommending using sync expressions for this purpose. Sync expressions cannot be used without cost, if you read the doc further you will notice the Scan vs Query operations on the sync query.

@HuiSF HuiSF added the pending-community-response Pending response from the issue opener or other community members label Jul 1, 2022
@scottbisaillon
Copy link

This feature (or lack of currently) is what is stopping me from using the amplify packages. I think being able to turn on/off sync at runtime is critical for any app wanting to offer tiered services. Offline first is already supported (which I think is great and very appealing which is what brought me to solution in the first place) so this seems to be a next logical step.

@dnys1
Copy link
Contributor

dnys1 commented Jul 26, 2022

@scottbisaillon I understand. Historically, it's been a limitation of AppSync, but they recently released support for enhanced subscription filtering which would solve this problem. We are currently working on integrating it into the Amplify CLI and expect it to make possible this and many more use cases.

@HuiSF
Copy link
Member

HuiSF commented Jul 27, 2022

Closing this issue in favor of this feature request tracking issue #1692 .
Please feel free to follow up, and post suggestions on this feature. Thanks.

@HuiSF HuiSF closed this as not planned Won't fix, can't repro, duplicate, stale Jul 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
datastore Issues related to the DataStore Category pending-community-response Pending response from the issue opener or other community members question A question about the Amplify Flutter libraries
Projects
None yet
Development

No branches or pull requests

5 participants