简体   繁体   中英

Removing firebase listener before signout

I noticed when I sign out there's a message that pops up and says "Client does not have permission to perform this operation" I thought the firebase rules that I set were the problem but it's not because the rules I have is required for my project.

How can I remove this message? Here is my code:

logoutbutton.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        FirebaseAuth fauth=FirebaseAuth.getInstance();
       
        fauth.signOut();
        Intent intent2 = new Intent(getContext(), MainActivity.class);
        startActivity(intent2);
    }
});

I tried changing the rules on firebase database and that did not help.

Most likely the client loses its permission to access the data when you sign the user out. In that case, the database server cancels the existing listeners on that data, which you see as a permission-denied error in the client.

If you want to prevent seeing that error message, you'll have to detach the listener that are about to be cancelled before signing out by calling removeEventListener on the same reference/query where you registered them.

Note that the error is harmless in this scenario, as it just logs the message and remove the listener - similar to what happens when you call removeEventListener . So the only reason to clean them up yourself is to get rid of the error message, the behavior won't change aside from that.

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