我不知道哪里出了问题。我正在使用Node.js,并尝试使用电子邮件/密码和谷歌身份验证登录。我已经在Firebase控制台中启用了所有这些。
npm Firebase版本- 3.1.0
部分代码:
var firebase = require('firebase');
var config = {
apiKey: "AIzaSyAH27JhfgCQfGmoGTdv_VaGIaX4P-qAs_A",
authDomain: "pgs-intern.firebaseapp.com",
databaseURL: "https://pgs-intern.firebaseio.com",
storageBucket: "pgs-intern.appspot.com",
};
firebase.initializeApp(config);
app.post('/login', function(req, res) {
var auth = firebase.auth();
firebase.auth().signInWithEmailAndPassword(req.body.login, req.body.password).catch(function(error) {
// Handle Errors here.
var errorCode = error.code;
var errorMessage = error.message;
// ...
});
}
错误: firebase.auth(...).signInWithLoginAndPassword不是函数或错误:我编写时firebase.auth(...).GoogleAuthProviders不是构造函数
firebase.auth().signInWithPopup(provider).then(function(result) {
// This gives you a Google Access Token. You can use it to access the Google API.
var token = result.credential.accessToken;
// The signed-in user info.
var user = result.user;
// ...
}).catch(function(error) {
// Handle Errors here.
var errorCode = error.code;
var errorMessage = error.message;
// The email of the user's account used.
var email = error.email;
// The firebase.auth.AuthCredential type that was used.
var credential = error.credential;
// ...
});
我只是完全按照文档中的说明做了。
发布于 2016-07-05 10:10:33
你的第一个错误可能来自某个地方的打字错误。
firebase.auth(...).signInWithLoginAndPassword is not a function
注意,它显示signInWithLoginAndPassword,函数名为signInWithEmailAndPassword.在发布的代码中,它被正确使用,所以它可能在其他地方。
firebase.auth(...).GoogleAuthProviders is not a constructor
您还没有将代码发布到使用它的位置,但我假设在创建在firebase.auth().signInWithPopup(provider)
中使用的provider
变量时会出现此错误
这行应该是var provider = new firebase.auth.GoogleAuthProvider();
根据错误消息,我认为您可能正在执行new firebase.auth().GoogleAuthProvider();
省略auth后面的括号,如果是这样的话。
发布于 2016-07-05 15:59:26
没有办法使用email+password或社交提供商将你的node.js应用程序登录到firebase。
服务器端进程使用所谓的服务帐户登录Firebase。关键的区别在于你初始化应用程序的方式:
var admin = require('firebase-admin');
admin.initializeApp({
serviceAccount: "path/to/serviceAccountCredentials.json",
databaseURL: "https://databaseName.firebaseio.com"
});
请参阅Firebase documentation for details on setting up a server-side process的此页面。
发布于 2017-02-09 17:49:47
不要通过Auth()函数调用GoogleAuthProvider。
根据文档,您必须创建一个GoogleAuthProvider实例。
let provider = new firebase.auth.GoogleAuthProvider()
请检查下面的链接https://firebase.google.com/docs/auth/web/google-signin
https://stackoverflow.com/questions/38200044
复制