如何使用uid删除Firebase用户?

时间:2020-10-02 11:19:35

标签: firebase flutter firebase-authentication

我有一个管理Web应用程序。我想通过传递uid删除用户。可以将flutter与firebase一起使用吗?谁能帮我吗?

1 个答案:

答案 0 :(得分:1)

使用客户端SDK,您只能删除自己的用户帐户。

如果要通过传递uid删除用户,则需要使用Admin SDKs之一,无论是从您控制的服务器还是通过Cloud Function。

例如,您可以从应用程序(网络,Flutter,iOS或Android)中调用Callable Cloud Function,该操作将删除给定的用户。

以下简化的Cloud Function代码可以解决问题:

const functions = require('firebase-functions');
const admin = require('firebase-admin');

admin.initializeApp();

exports.deleteUser = functions.https.onCall(async (data, context) => {

    try {
        // Potentially verify that the user calling the CF has the right to delete users

        await admin.auth().deleteUser(data.uid);
        return { result: 'user successfully deleted'};
    } catch (error) {
        throw new functions.https.HttpsError(...)   // See https://firebase.google.com/docs/functions/callable#handle_errors
    }

});

您将找到here如何从Web应用程序中调用以及如何here从Flutter应用程序中调用。

相关问题