Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
341 views
in Technique[技术] by (71.8m points)

android - Clear firebase persistence after logout

  1. Is there any way to clear data stored in Firebase Database persistence enabled via setPersistenceEnabled(true)?
  2. Or eventually prevent read access to previously stored users data on the device?
  3. And extra question - is there any way to check if any data is waiting to sync?

In my app I want to clear db when user is logging out and he confirm that unsynchronized changes will be removed. This app will be used on tablet by many people, and there'll be many data stored per user, so I want to clear unnecessary data stored on the device to:

  • shrink storage usage
  • prevent unauthorized person from read users data

It's a security flaw because any user, regardless of whether is signed in or not, has read access to all previously downloaded data! Fortunately we haven't write access there.

I?tried to clear db on my own, in both offline and online mode, but data still persist on the device:

// first clear all data on my own
FirebaseDatabase db = FirebaseDatabase.getInstance();
db.goOffline(); // even when I clear db in online mode data persist on mobile device
db.getReference().setValue(null);

// and then logout
FirebaseAuth.getInstance().signOut();
db.goOnline();

eg data structure:

{
  "someList": {
    "userId1": {
      "itemId11": {
        "name": "name 11"
      },
      "itemId12": {
        "name": "name 12"
      },
      ...
      "itemId1N": {
        "name": "name 1N"
      }
    }
    "userId2": {
      "itemId21": {
        "name": "name 21"
      },
      "itemId22": {
        "name": "name 22"
      },
      ...
      "itemId2N": {
        "name": "name 2N"
      }
    }
  }
}

my rules:

{
  "rules": {
    ".read": "false",
    ".write": "false",
    "someList": {
      "$uid": {
        ".read": "$uid === auth.uid",
        ".write": "$uid === auth.uid"
      }
    }
  }
}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...