我的工作是管理员网站,实际上我需要知道如何注册用户,而不失去我的管理注册,因为我需要使只有管理员可以创建用户帐户。我正在使用firebase电子邮件/Pw认证。
const CreateCh = document.querySelector('#CreateChaufeurs');
CreateCh.addEventListener('submit',(e)=>{
e.preventDefault();
//get chaufeur info
const email = CreateCh['exampleEmail11'].value;
const password = CreateCh['examplePassword11'].value;
const Fname = CreateCh['Fname'].value;
const Address = CreateCh['exampleAddress'].value;
const Tel = CreateCh['exampleAddress2'].value;
const Ville = CreateCh['exampleCity'].value;
const Etat = CreateCh['exampleState'].value;
const Cp = CreateCh['exampleZip'].value;
const AGE = CreateCh['AGE'].value;
console.log(password, email, Fname,AGE,Address,Tel,Ville,Etat,Cp );
firebase.auth().createUserWithEmailAndPassword(email, password).catch(function(error) {
// Handle Errors here.
var errorCode = error.code;
var errorMessage = error.message;
// ...
});
});但是在创建帐户之后,它会自动登录到那个新帐户。
发布于 2019-12-27 13:36:22
您可以初始化一个单独的Firebase实例来处理所有帐户创建请求。
在最简单的形式中,您可以使用:
let authWorkerApp = firebase.initializeApp(firebase.app().options, 'auth-worker');
let authWorkerAuth = firebase.auth(authWorkerApp);
authWorkerAuth.setPersistence(firebase.auth.Auth.Persistence.NONE); // disables caching of account credentials
authWorkerAuth.createUserWithEmailAndPassword(email, password).catch(function(error) {
// Handle Errors here.
var errorCode = error.code;
var errorMessage = error.message;
// ...
});如果您遇到诸如Firebase应用程序‘auth’已经初始化的错误,您可以将其封装在一个安全的getter中以避免这样的错误:
function getFirebaseApp(name, config) {
let foundApp = firebase.apps.find(app => app.name === name);
return foundApp ? foundApp : firebase.initializeApp(config || firebase.app().options, 'auth-worker');
}
let authWorkerApp = getFirebaseApp('auth-worker');https://stackoverflow.com/questions/59499570
复制相似问题