可以制作自己的Firebase密码电子邮件链接。

huangapple go评论51阅读模式
英文:

Is it possible to make my own firebase password email link

问题

我在使用Firebase身份验证时遇到问题。我有一个主用户需要创建其他用户,但问题是,一旦创建了帐户,应用程序关闭后密码不再可见。我考虑为每个新用户发送电子邮件密码重置的方法,但每天只允许150个请求。我可以使用我的SMTP服务器来处理此操作并具有无限请求吗?我的后端是ASP.NET,所以将整个用户身份验证过程移到那里是否更好?

我尝试为新用户每次发送密码重置电子邮件,但每天只允许150个请求。

英文:

I have an issue with using Firebase auth. I have a main user who needs to create other users, but the problem is that once an account is created, the password is no longer visible after the application is closed. I had the idea of sending an email password reset for each new user, but there are only 150 requests allowed per day. Can I use my SMTP server to handle this and have unlimited requests? I have my backend on ASP.NET, so would it be better to move the entire user authentication process there?

I tried sending password reset emails each time for new user, but there are only 150 request allowed per day.

答案1

得分: 0

Firebase身份验证上创建新用户帐户的责任应该由用户自己来承担。预先创建帐户是一种反模式。

推荐的方法是通过常规电子邮件服务器发送普通的邀请链接,供用户在您的应用上创建帐户,这与Firebase无关。然后,每个点击链接的用户可以自行注册,设置他们的密码,这样你就不会超过配额限制。

如果你想限制谁可以在你的应用上注册,请参阅阻止云函数文档,其中包含将注册限制为特定域的示例:

exports.beforeCreate = functions.auth.user().beforeCreate((user, context) => {
  // (如果用户在租户上下文中进行身份验证,可以从user.tenantId或context.resource中确定租户ID,例如'projects/project-id/tenant/tenant-id-1')

  // 只有特定域的用户可以注册。
  if (user.email.indexOf('@acme.com') === -1) {
    throw new functions.auth.HttpsError('invalid-argument', `未经授权的电子邮件"${user.email}"`);
  }
});

你可以根据需要修改这个示例,例如使其从允许的电子邮件地址列表中运行(目前正试图预先创建帐户的人)。

英文:

The creation of a new user's account on Firebase Authentication should be left to that user themselves. Pre-creating accounts is an anti-pattern.

The recommended approach is to send a normal invite link through your regular email server for the users to create an account on your app, something that doesn't involve Firebase at all. Then each user who clicks the link can sign-up themselves, set their password on sign-up, and you won't hit the quota limit.

If you want to restrict who can sign up to your app, have a look at the documentation on blocking Cloud Functions, which contains this example of limiting signup to a specific domain:

exports.beforeCreate = functions.auth.user().beforeCreate((user, context) => {
  // (If the user is authenticating within a tenant context, the tenant ID can be determined from
  // user.tenantId or from context.resource, e.g. 'projects/project-id/tenant/tenant-id-1')

  // Only users of a specific domain can sign up.
  if (user.email.indexOf('@acme.com') === -1) {
    throw new functions.auth.HttpsError('invalid-argument', `Unauthorized email "${user.email}"`);
  }
});

You can modify this to fit your needs, for example make it work from a list of allowed email addresses (the people who are currently trying to pre-create accounts for).

huangapple
  • 本文由 发表于 2023年4月6日 20:54:36
  • 转载请务必保留本文链接:https://go.coder-hub.com/75949770.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定