如何在Web的Firebase中删除未验证的电子邮件? [英] How can I delete not verified emails in Firebase in web?

查看:60
本文介绍了如何在Web的Firebase中删除未验证的电子邮件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个函数,该函数使用Firebase在Angular 6中使用电子邮件和密码进行注册.

I created a function that signs up with email and password in Angular 6 with Firebase.

然后我发送一封电子邮件以验证电子邮件,然后有时用户转到他的电子邮件并进行验证.

Then I send an email to verify email, then some times user go to his email and verify.

这听起来不错,其他人不去验证电子邮件,因此它仍在我的Firebase中.

That's sound good, others don't go to verify email so it's still in my Firebase.

我希望Firebase内有任何功能能够自动删除超过两天未验证的电子邮件.

I want any function inside Firebase that automatically remove emails that not verified for more than two days.

推荐答案

对于客户而言,绝对没有办法.您必须为此使用NodeJS Firebase Admin SDK.

There's definitely no way of doing this for Clients. You will have to use the NodeJS Firebase Admin SDK for this.

我认为没有直接的方法可以做到这一点.您可以尝试将listUsers方法与deleteUser方法链接在一起.在删除用户之前,您可以检查该用户是否未经验证.

I don't think there's a straight-forward way of doing this. You could try chaining the listUsers method along with deleteUser method. Before deleting a user, you could check if the user is not verified.

此脚本准备就绪后,只需将其部署为Firebase Cloud Function.

Once this script is ready, just deploy it as a Firebase Cloud Function.

我不确定如何每2天运行一次.

I'm not sure how to run this every 2 days.

我不确定这是否行得通.但是您可能想尝试一下:

I'm not sure if even this would work. But you might want to give this a try:

function listAllUsers(nextPageToken) {
  // List batch of users, 1000 at a time.
  admin.auth().listUsers(1000, nextPageToken)
    .then(function(listUsersResult) {
      listUsersResult.users.forEach(function(userRecord) {
        const user = userRecord.toJSON();
        if (!user.emailVerified) {
          admin.auth().deleteUser(user.uid)
            .then(function() {
              console.log("Successfully deleted user");
            })
            .catch(function(error) {
              console.log("Error deleting user:", error);
            });
        }
      });
      if (listUsersResult.pageToken) {
        // List next batch of users.
        listAllUsers(listUsersResult.pageToken)
      }
    })
    .catch(function(error) {
      console.log("Error listing users:", error);
    });
}

// Start listing users from the beginning, 1000 at a time.
listAllUsers();

这篇关于如何在Web的Firebase中删除未验证的电子邮件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆