I am following newest version of Firebase Google Web SDK. Everything from login to sign up and sign out works just fine. I want to let users delete their own accounts and followed the API reference for firebase.User
class. Also I read their docs about managing users.
This is the code I use:
function deleteAccount () {
console.log('delete account!!')
const auth = firebase.auth()
console.log({auth})
auth.delete().then(function () {
console.log('delete successful?')
const user = firebase.auth().currentUser
console.log({user})
store.dispatch(forgetUser())
routerReset('GetStarted')
}).catch(function (error) {
console.log({error})
// An error happened.
})
}
The function delete
appears to work from firebase.Auth
object and resolves the promise. If doing the same with signOut
the log presents an undefined object, however here:
console.log({user}) // { user: Firebase.User object }
No error is emitted.
NOTE: this is a react-native app.
I am following newest version of Firebase Google Web SDK. Everything from login to sign up and sign out works just fine. I want to let users delete their own accounts and followed the API reference for firebase.User
class. Also I read their docs about managing users.
This is the code I use:
function deleteAccount () {
console.log('delete account!!')
const auth = firebase.auth()
console.log({auth})
auth.delete().then(function () {
console.log('delete successful?')
const user = firebase.auth().currentUser
console.log({user})
store.dispatch(forgetUser())
routerReset('GetStarted')
}).catch(function (error) {
console.log({error})
// An error happened.
})
}
The function delete
appears to work from firebase.Auth
object and resolves the promise. If doing the same with signOut
the log presents an undefined object, however here:
console.log({user}) // { user: Firebase.User object }
No error is emitted.
NOTE: this is a react-native app.
Share Improve this question asked Sep 22, 2016 at 8:59 jsdariojsdario 6,85311 gold badges44 silver badges78 bronze badges2 Answers
Reset to default 7You seem to be missing a reference to currentUser
.
From the Firebase documentation on deleting a user:
You can delete a user account with the
delete
method. For example:var user = firebase.auth().currentUser; user.delete().then(function() { // User deleted. }, function(error) { // An error happened. });
Important: To delete a user, the user must have signed in recently. See Re-authenticate a user.
As said, your code doesn't reference currentUser
. I'm not sure what calling delete
on the auth object itself does.
Update: I just ran this to validate the behavior:
firebase.auth().currentUser.delete().then(function () {
console.log('delete successful?')
console.log(app.auth().currentUser)
}).catch(function (error) {
console.error({error})
})
At first I got a 400, with the body of the response saying that it'd been too long since I signed in. After re-authenticating and trying again, I got:
delete successful?
null
To delete a user, the user must have signed in recently.