最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Using IndexedDB data across multiple users - Stack Overflow

programmeradmin1浏览0评论

I am trying to determine the best way to create a "Save" functionality for my application and have pondered upon using IndexedDB to achieve this. I've read some documentation on IndexedDB, but I've been unable to find an answer to my question:

In my application, users have logins and can make data changes. The idea here is, that after hitting Save, this data would get stored somewhere and other users who log in would be able to see those changes and make other modifications if needed, etc. Now, my question is, given that other users need to be able to see the changes another user makes, is IndexedDB suitable for this? Or is IndexedDB session based, where the changes could only be viewed locally?

If these changes are limited to being viewed locally, that means that my only option would be to store these changes in the back-end, and hitting the database as many times as a user saves data doesn't seem like a feasible solution. Here is my approach given this case:

  1. Upon hittin "Save", send a flag to the back-end denoting this as a save
  2. Check if the entry exists, and if it doesn't, store it in the database (without validating) as an insert. Add the flag to the DB. If the entry exists, store as an update.
  3. If the user submits (different than save) perform a data validation and update the entry in the DB.

This is the best approach I could think of if IndexedDB is not an option. Would there be a better way to achieve this, theoretically? Thanks in advance.

I am trying to determine the best way to create a "Save" functionality for my application and have pondered upon using IndexedDB to achieve this. I've read some documentation on IndexedDB, but I've been unable to find an answer to my question:

In my application, users have logins and can make data changes. The idea here is, that after hitting Save, this data would get stored somewhere and other users who log in would be able to see those changes and make other modifications if needed, etc. Now, my question is, given that other users need to be able to see the changes another user makes, is IndexedDB suitable for this? Or is IndexedDB session based, where the changes could only be viewed locally?

If these changes are limited to being viewed locally, that means that my only option would be to store these changes in the back-end, and hitting the database as many times as a user saves data doesn't seem like a feasible solution. Here is my approach given this case:

  1. Upon hittin "Save", send a flag to the back-end denoting this as a save
  2. Check if the entry exists, and if it doesn't, store it in the database (without validating) as an insert. Add the flag to the DB. If the entry exists, store as an update.
  3. If the user submits (different than save) perform a data validation and update the entry in the DB.

This is the best approach I could think of if IndexedDB is not an option. Would there be a better way to achieve this, theoretically? Thanks in advance.

Share Improve this question asked Aug 19, 2017 at 19:06 user2554121user2554121 2251 gold badge8 silver badges18 bronze badges 2
  • 1 can you save stuff server side? – Daniel A. White Commented Aug 19, 2017 at 19:08
  • Yes, that's possible. – user2554121 Commented Aug 19, 2017 at 19:35
Add a ment  | 

3 Answers 3

Reset to default 4

indexedDB is stored per origin per browser client. If you have multiple users on the same puter, each using the same browser, and visiting the same origin, then yes, you can easily store information for different users in the same indexedDB database.

  • It will not be secure, and this is not avoidable. Anyone who opens devtools can inspect the contents of the database.
  • Any user can remove all data in the database at any time for any reason, and this is also not avoidable.

Only store encrypted data in indexedDB, set keys to distinguish the records for each user, and bind different decryption key to different users.

In this way, even other users can see the records rows, but never can read the real content except his own records.

If you have multiple users on the same puter, each using the same browser, and visiting the same origin, then yes, you can easily store information for different users in the same indexedDB database.

How you setup the system, to grant this behaviour? You create a mon folder for all users in the filesystem? I see that Indexed DB data are stored here: C:\Users\XXXXXX\AppData\Local\Google\Chrome\User Data\Default\IndexedDB

发布评论

评论列表(0)

  1. 暂无评论