无需登录即可调用方法createUserWithEmailAndPassword [英] call method createUserWithEmailAndPassword without doing signIn
问题描述
在我的系统中,我需要从经过身份验证的用户创建用户,但是为此,我需要通过 createUserWithEmailAndPassword
方法创建用户,并且当我通过此方法创建用户时,身份验证状态将更改为当前创建的用户.
In my system I need to create users from an authenticated user, but for this I need to create a user through the createUserWithEmailAndPassword
method and when I create the user through this method the authentication status changes to the user that was created at the moment.
是否有一种方法可以从经过身份验证的用户创建用户,而无需通过 createUserWithEmailAndPassword
方法创建的用户进行登录?
Is there a way to create users from an authenticated user without making signIn for the user created after it was created by the createUserWithEmailAndPassword
method?
我有一个使用Angular + Node.js开发的系统
createUser(user: Usuario): Promise<firebase.auth.UserCredential> {
return this._angularFireAuth.auth.createUserWithEmailAndPassword(user.email, user.password);
}
推荐答案
[ANSWER]
您可以在客户端中创建新的Firebase App上下文,然后再次调用createUserWithEmailAndPassword().这不会重新验证到创建的新用户.参考.
You can create a new Firebase App context in your client and then call createUserWithEmailAndPassword() again. This will not be re-authenticate to the the new user created. Reference.
var authApp = firebase.initializeApp({
// ...
}, 'authApp');
var detachedAuth = authApp.auth();
detachedAuth.createUserWithEmailAndPassword('foo@example.com', 'asuperrandompassword');
执行此操作时可能出现的问题是:名为"[DEFAULT]"的Firebase应用已存在(app/duplicate-app).
Potential Problem when doing this is: Firebase App named '[DEFAULT]' already exists (app/duplicate-app).
[其他场景(供其他参考)]
我认为您的意思是其中之一:
I assume you meant either one of these:
-
您希望登录的用户即使在关闭浏览器后仍保持登录状态.在这种情况下,您可以使用 firebase身份验证提供的持久性.
当用户状态从未登录"更改为已登录"时,您想隐藏登录按钮.然后,您可以查看此帖子.
You want to hide your sign-in button when the user state change from "not signed-in" to "signed-in". Then you can check this post.
其他参考:如何保持用户无论如何都可以使用Firebase登录?
希望有帮助!
这篇关于无需登录即可调用方法createUserWithEmailAndPassword的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!