首页 > 解决方案 > 如何删除使用自定义令牌创建的 FirebaseAuth currentUser

问题描述

如果他们使用标准提供商之一(例如谷歌)登录,我在删除当前用户时没有任何问题。

但是,当我使用await FirebaseAuth.instance.currentUser.delete()自定义令牌登录的用户(在我的实例中,使用 Firebase Admin 在具有 LINE 令牌的云功能中创建)时,我没有收到任何错误,但用户也没有被删除当我检查控制台时 Firebase。

我的删除用户代码:

Future<void> deleteAccount() async {
    try {
      await FirebaseAuth.instance.currentUser.delete();
    } on FirebaseAuthException catch (e, s) {
      if (e.code == 'requires-recent-login') {
        print(
            'The user must reauthenticate before this operation can be executed.');
        await signInWithLine();
        await FirebaseAuth.instance.currentUser.delete();
      } else {
        print('Firebase auth delete account error:\n$e');
        print('============stack=========\n$s');
      }
    } catch (e, s) {
      print('Firebase auth delete account error:\n$e');
      print('============stack=========\n$s');
    }
  }

FirebaseAuth.instance.signInWithCustomToken(customToken)如果他们的身份验证记录是用而不是创建的,我是否错过了删除用户需要采取的额外步骤FirebaseAuth.instance.signInWithCredential(oauthCredential)

标签: flutterfirebase-authenticationgoogle-cloud-functions

解决方案


推荐阅读