首页 > 解决方案 > 如何在颤动中自动注销firebase用户?

问题描述

我正在开发一个以 firebase 作为后端和身份验证的颤振应用程序,
现在我希望该应用程序有一个试用版,用户可以在其中登录并使用具有完整功能的应用程序(大约一小时),然后退出在那一小时结束后自动。

到目前为止,我完成了以下工作:
1- 使用 google 帐户登录。
2-使用时间戳添加登录用户
_trial collection

Future enterTrial() async {
    final UserCredential user = await Auth.instance.googleSignInMethod();
    final User actualUser = user.user;
    try {
        //_trial is a collection for users in Trial Period
      await _trial.doc(actualUser.email).set({.   
        "name": actualUser.displayName,
        "email": actualUser.email,
        "creationDate": FieldValue.serverTimestamp(),
      });
    } catch (e) {
      print(e);
    }
  }

剩下的:
从登录一小时后,注销并将用户从 移动
_trial collection _expired collection.

这样我就可以检查用户是否已过期。
有没有办法在一段时间后自动注销?或定期比较creationTime 与currentTime 并相应地signOut?
提前致谢。

标签: firebaseflutterfirebase-authenticationfirebase-cloud-messagingflutter-dependencies

解决方案


是的,您可以通过使用background_fetch包来实现这一点,这为您提供了一个回调函数,您可以在该函数中调用您的注销方法。


推荐阅读