我们如何在node.js中使用Firebase Auth创建用户? [英] How can we create a user with Firebase Auth in node.js?

查看:150
本文介绍了我们如何在node.js中使用Firebase Auth创建用户?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正尝试在nodejs中使用Firebase身份验证创建用户帐户。它不起作用,我不知道为什么。这里是代码和nodejs产生的错误:

  var config = {.......}; //我不能共享配置

var app = firebase.initializeApp(config);

var db = app.database();
var auth = app.auth();
$ b auth.createUserWithUsernameAndPassword(anemail@gmail.com,@NewPassWord)。然后(
函数(用户){console.log(user);},
函数(错误){console.error(error);}
);

NodeJS产生错误:

<$ p $在Object中没有方法'createUserWithUsernameAndPassword'
< anonymous> (/home/antonio/Projects/firebase/app.js:20:6)
在Module._compile(module.js:456:26)
在Object.Module._extensions..js(module .js:474:10)
at Module.load(module.js:356:32)
at Function.Module._load(module.js:312:12)
at Function。
在启动时(node.js:119:16)
在node.js:906:3


解决方案

嗯,我不认为方法createUserWithUsernameAndPassword works,

用这个来代替 createUserWithEmailAndPassword



当firebase使用电子邮件时,您使用了用户名


I'm trying to create user account using Firebase auth in nodejs. It doesn't work and I don't know why. Here's the code and the error generated by nodejs:

var config = {.......}; // i can't share the config

var app = firebase.initializeApp(config);

var db = app.database();
var auth = app.auth();

auth.createUserWithUsernameAndPassword("anemail@gmail.com", "@NewPassWord").then(
    function(user){ console.log(user);},
    function(error){ console.error(error);}
);

Error generate by NodeJS:

TypeError: Object [object Object] has no method 'createUserWithUsernameAndPassword'
    at Object.<anonymous> (/home/antonio/Projects/firebase/app.js:20:6)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Function.Module.runMain (module.js:497:10)
    at startup (node.js:119:16)
    at node.js:906:3

解决方案

well, I don't think that the method "createUserWithUsernameAndPassword" works,

Use this instead createUserWithEmailAndPassword

you used username when firebase use email

这篇关于我们如何在node.js中使用Firebase Auth创建用户?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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