简体   繁体   中英

Angular + Firebase Delete user on logout

I'm developing and application using angular 4 and firebase. In this I'm giving access to the user with a login (email and password) and as guest (using anonymous auth), but I want to delete the user if the user is a guest (anonymous auth user) when he logs out of the application.

How can I delete a user from firebase auth, not from the realtime database or the firestore database, from the auth section of firebase?

One option is to create two logout button and show using *ngIf . If user is logged in as anonymous you need to perform delete user rather than logout.

var user = firebase.auth().currentUser;

user.delete().then(function() {
  // User deleted. Redirect to login page...
}).catch(function(error) {
  // An error happened.
});

Or you can first do a check inside your logout function and proceed user.isAnonymous

logout(){
    var user = firebase.auth().currentUser;
    if(user.isAnonymous){
        user.delete().then(function() {
          // User deleted. Redirect to login page...
        }).catch(function(error) {
          // An error happened.
        });
    }else{
        //perform logout
    }
}

check this doc for more info

( i didn't tested code myself. )

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