Reputation: 386
I want to delete user from firebase using uid, It requires using Firebase Admin SDK but I have an error while calling the cloud function
the function code
const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);
exports.deleteUserByUID = functions.https.onRequest(async (request, response) => {
const userID = request.body.uid;
admin.auth().deleteUser(userID)
.then(() => {
console.log('Successfully delete user.')
response.status(200).send('Deleted User')
return
})
.catch(error => {
console.log('Error deleting user:', error)
response.status(500).send('Failed')
})
})
calling function
var functions = Functions.functions()
functions.httpsCallable("deleteUserByUID").call(["uid": "M6AgnfIIlmXvjfXlgEGEE1ieDrf1"]) { (result, error) in
if error != nil {
print(error)
}
print result : Error Domain=com.firebase.functions Code=13 "INTERNAL" UserInfo={NSLocalizedDescription=INTERNAL}
Upvotes: 0
Views: 313
Reputation: 317372
You are mixing up callable functions with normal HTTP functions. They don't work the same way.
Your function is a normal HTTP function, but you're trying to call it using the Firebase library for invoking callable type functions. This won't work. The client SDK only works with callable functions as you see in the documentation. Please read that documentation thorough to understand how callable functions work.
If you want to keep using a normal HTTP function, you should invoke it instead with a standard HTTP client library.
Upvotes: 2