How to block users by app version in Firebase

放肆的年华 提交于 2019-12-11 15:21:39

问题


I have an Android app that use Firebase for general chat room. Users enter their nickname and start to chat.

There is no problem about implementation, my application works well. But the problem is about data usage. Data usage was too high because of wrong implementation.

in app version 14

I was fetching all data in chat room, then show the last 100. This situation causes high usage in firebase data. There was daily 1-2GB download usage for 2k users. In fact it should be less.

Then, a week ago, I learned limitToLast(x) function.

https://firebase.google.com/docs/database/admin/retrieve-data

Then I decided to update my app.

in app version 15

I added limitToLast(100) function to required lines in my code. Now, there is no problem for my 15-ver users. Daily data usage dropped to 100MB per day.

Recently, my data usage rised to 300-400MB, daily.

This is because you know there are hundreds of apk sites.

1- These apk sites do not always contain last version.

2- There are some users do not update my app.

As a result, there are some users that uses my app below 15 version. These users causes data usage problem because in version 14 the code was problematic and caused high data usage problem.

How can I block these users in firebase with rules?

for now it is like this:

{
  "rules": {
    ".read": true,
    ".write": true
  }
}

I want a code like this:

{
  "rules": {
    ".read": "if app version is greater than 14",
    ".write": "if app version is greater than 14"
  }
}

Can I do this with rules? How can I do? If no, is there any other ways to block users who uses low versions.


回答1:


There is no way to pass such information with each request to the database.

The closest thing I can think of is setting it as a custom claim for the user, which is passed to the database and security rules. But a single user could be using different versions of the app on different devices, so that mapping won't work correctly.

The best way would be to have a single node with the minimum client version (or if you want: the version of the data model) in the database:

minimumClientVersion: 15

Then when the app starts, read this number, check it against the app version, and tell the user to upgrade of their app is not up to date.



来源:https://stackoverflow.com/questions/50429782/how-to-block-users-by-app-version-in-firebase

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!