How can i store and get user wise data (Cognito + DataStore) in mobile application

0

Hello Team i made 1 POC where i am able to complete all the steps for Cognito as well as i am able to save data in DynamoDB Using app sync with 1 class

now i want to modify/update that poc as i want to store/save the data user wise and get only those records that are save by particular user

for eg i have 2 Users namely A and B (Created using cognito) now i have 1 object as Asset which is in DynamoDB where users can perform CURD operations

so if User A added Asset 1, Asset2 , Asset 3 and User B added Asset 4, Asset 5

So when i login through cognito User A i only want to fetch records of Assets which belongs to User A i.e Asset 1, Asset2 , Asset 3 and like wise

Can you please guide me how can i do that What exactly needs to do for this ? how cognito user and data related to each other

i am a mobile application developer iOS doing all above stuff using Swift

Thanks

1 Answer
0

Based on your question, I understand that you have created a proof of concept (POC) in which users are authenticated using AWS Cognito services and their data is stored in DynamoDB as assets. Now, you want to modify your POC to store assets specific to each user so that when a user logs in, they can only view and manipulate the assets that they have created.

You will need to change your current architecture to accomplish this. Each asset record should contain a user identity so that you may filter the assets according to the user who created them.

To modify your POC, you can follow these steps: Add a property to the Asset object that will contain the user identification in the data model. This field may be the Cognito user ID of the user that generated the asset.

When generating an asset, the CRUD operations should be changed to include the user ID, and when fetching assets, the entries should be filtered based on the user ID. This may be done by utilising AWS AppSync VTL (Velocity Template Language).

Modify the authorization rules in your AWS AppSync API to ensure that each user can only access their own assets. You can use the $ctx.identity.userId context variable to accomplish this.

By making these changes, your AWS AppSync API can retrieve and store assets based on the user who created them, allowing each user to view and manipulate only their own resources.

answered a year ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions