简体   繁体   中英

Why do I get an error when I log out with Firebase Auth?

this is my logout code:

  onPressed: () async {
                await FirebaseAuth.instance.signOut();
                await widget.checkLogin();
              },

This is my CheckLogin function:

  checkLogin() async {
    if (FirebaseAuth.instance.currentUser != null) {
      login = true;
      setState(() {});
    } else {
      login = false;
      setState(() {});
    }
  }

 

The error it gives me after logging out is the following:

Unhandled Exception: [firebase_database/permission-denied] Client doesn't have permission to access the desired data.

With various attempts I realized that the problem lies in these lines of code, but I don't know how to fix...

      if (FirebaseAuth.instance.currentUser != null) {
  WidgetsBinding.instance.addPostFrameCallback((_) async {
    DatabaseReference ref = FirebaseDatabase.instance.ref("temp");
    if (FirebaseAuth.instance.currentUser != null) {
      ref.onValue.listen((DatabaseEvent event) {
        final snapshot = event.snapshot.value;
        if (snapshot != null) {
          Object? temp = snapshot;

          if (mounted) {
            setState(() {});
          }
        }
      });
    }
  });
}

Anyone know how to fix?

Go to Your Firebase Console And Update your rules like this

Select Database From Side Menu --> Select Rule From tabs above --> Update your rule like this

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

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