首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在不登录firebase/js的情况下注册用户

如何在不登录firebase/js的情况下注册用户
EN

Stack Overflow用户
提问于 2019-12-27 10:44:00
回答 1查看 2.1K关注 0票数 1

我的工作是管理员网站,实际上我需要知道如何注册用户,而不失去我的管理注册,因为我需要使只有管理员可以创建用户帐户。我正在使用firebase电子邮件/Pw认证。

代码语言:javascript
复制
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;
    // ...
  });
});

但是在创建帐户之后,它会自动登录到那个新帐户。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-12-27 13:36:22

您可以初始化一个单独的Firebase实例来处理所有帐户创建请求。

在最简单的形式中,您可以使用:

代码语言:javascript
复制
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中以避免这样的错误:

代码语言:javascript
复制
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');
票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/59499570

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档