0

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?

1 Answer 1

3

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.)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.