如何在不登录的情况下通过 Firebase 身份验证创建新用户? [英] How can I create a new user via Firebase Auth without signing in?

查看:22
本文介绍了如何在不登录的情况下通过 Firebase 身份验证创建新用户?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个企业应用程序,管理员可以在其中创建新用户(没有注册表单).我正在使用 Firebase Auth,它在很多方面都很棒,但我的用例遇到了问题.当您使用 firebase.auth().createUserWithEmailAndPassword(email, password) 时,由此创建的用户会自动登录.当管理员创建用户帐户时,这显然不起作用.有什么办法可以避免这种行为吗?谢谢.

I'm working on an enterprise application in which administrators create new users (there is no sign-up form). I am using Firebase Auth, which is great in many ways, but I've come across a problem for my use case. When you use firebase.auth().createUserWithEmailAndPassword(email, password), the user thereby created is automatically signed in. This obviously won't work when an admin is creating the user accounts. Is there any way to avoid this behavior? Thanks.

推荐答案

这是Firebase 管理 SDK.您不是在客户端创建用户,而是在托管环境中创建用户,例如服务器或 Cloud Functions.当您想要添加新用户时,您让客户端调用您的端点.此 codelab 展示了如何使用 Firebase Admin Auth SDK 合并自定义声明.这与您正在寻找的内容略有不同,但它可以让您朝着正确的方向开始.

This is a good use case for the Firebase Admin SDKs. Instead of creating the user client-side, you create the user in a managed environment, like a server or Cloud Functions. You have the client make a call to your endpoint when you want to add a new user. This codelab shows how to incorporate custom claims using the Firebase Admin Auth SDK. This is a little different from what you're exactly looking for, but it can get you started in the right direction.

这篇关于如何在不登录的情况下通过 Firebase 身份验证创建新用户?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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