简体   繁体   中英

How to block users by app version in Firebase

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.

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.

A way to block access to the database depending on the realtime database schema version is to have a root node with the version of your database schema. For example : /v3/users, /v3/messages...etc

That way only versions of your app calling realtime db with the good database versions have access to the database.

But that's a thing you should implement before spotting this problem.

I would implement a check app version routine when the app is launched. If the app version is lower than required version (which is merely a remote config string parameter) then I'd display a view that has only an upgrade button + an explanation stating they need to upgrade. View cannot be dismissed.

Ofc. you cannot reach the current users out there but in time or within 7 days most people have upgraded to a newer version of the app: the problem goes away gradually.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM