![](/img/trans.png)
[英]Firebase Authentication: Create self defined expiry token with Firebase
[英]Firebase authentication, firebase is not defined
我试图为我的firebase项目创建一个登录页面,但总是当我将params发送到函数时它返回“Firebase未定义。这是我的代码:
<button id="login" onclick="signIn()"><Login</button>
函数signIn()仅将href更改为http:// localhost:5000 / signin /:email /:password
那我有这个
const functions = require('firebase-functions');
const adm = require('firebase-admin');
const express = require('express');
const signin = require('./modules/signin');
const firebase = require("firebase");
// // Create and Deploy Your First Cloud Functions
adm.initializeApp(
functions.config().adm
);
const app = express();
app.get('/signin/:email/:password', (request, response) => {
exports.signin = signin(request.params.email, request.params.password);
});
exports.app = functions.https.onRequest(app);
而我的功能只是
function signin (email, password) {
firebase.auth().signInWithEmailAndPassword(email, password).then(function(user) {
// user signed in
console.log ("Usuário logado com sucesso!");
return True;
}).catch(function(error) {
var errorCode = error.code;
var errorMessage = error.message;
if (errorCode === 'auth/wrong-password') {
// alert('Wrong password.');
return false;
} else {
alert(errorCode+": "+errorMessage);
return false;
}
});
}
module.exports = signin;
我试图在函数文件夹上使用index.js作为一种“控制器”来调用后端的函数,但我很难解决这个简单的问题。
您无法在云功能中使用Firebase客户端SDK。 云功能被视为后端代码,不能在浏览器上运行。 如果要登录用户,则必须在浏览器代码中使用SDK,而不是后端代码。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.