我用"node firebasedb.js"启动我的节点.我的firebasedb.js包含以下代码:
var admin = require("firebase-admin");
var serviceAccount = require("service_account.json");
// Initialize Firebase
var config = {
credential: admin.credential.cert(serviceAccount),
apiKey: "<api key>",
authDomain: "<auth domain>",
databaseURL: "<database url>",
storageBucket: "<storage bucket>",
};
admin.initializeApp(config);
Run Code Online (Sandbox Code Playgroud)
当我运行节点时,我在.json文件所在的目录中.但它说
Error: Cannot find module 'service_account.json'
Run Code Online (Sandbox Code Playgroud) 因此,Firebase提供了一种称为"功能"的功能,它本质上是一个nodejs服务器,它具有预先配置的所有Firebase内容,并自动处理所有缩放.我想知道,有没有办法从角度2应用程序调用"函数"index.js文件中的函数?
我需要利用firebase-admin npm模块检查用户的电子邮件是否存在,然后获取该用户的uid(如果有).
根据此链接,我可以设置我的index.js文件,例如:
const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);
// I'm actually not sure if this is how you do this part:
exports.getUserByEmail = (email) => {
return admin.auth().getUserByEmail(email);
}
Run Code Online (Sandbox Code Playgroud)
有没有办法getUserByEmail()在Angular 2应用程序中调用组件内部?
提前致谢!
有没有办法从我的服务器发送电子邮件验证电子邮件?
这是在客户端上完成的方式:
authData.sendEmailVerification().then(function() {
Run Code Online (Sandbox Code Playgroud)
有没有办法在服务器上做到这一点?
我在云函数上使用 firebase admin SDK 来创建用户
admin.auth().createUser({
email: someEmail,
password: somePassword,
})
Run Code Online (Sandbox Code Playgroud)
现在我希望用户使用登录signInWithEmailAndPassword('someEmail', 'somePassword')但我不能。我收到以下错误
{code: "auth/user-not-found", message: "There is no user record corresponding to this identifier. The user may have been deleted."}
Run Code Online (Sandbox Code Playgroud) const firebase = require('@firebase/app').default;
require('@firebase/firestore')
const admin = require('firebase-admin')
const functions = require('firebase-functions')
// initialize the admin SDK...
exports.setUpdatedDate = functions.firestore.document('/foos/{fooId}/bars/{barId}')
.onCreate(event => {
admin.firestore().collection('foos').doc( event.params.fooId )
.set({
updatedDate: firebase.firestore.FieldValue.serverTimestamp()
}, {merge:true})
})
Run Code Online (Sandbox Code Playgroud)
运行上面的函数shell,我得到:
Cannot encode type ([object Object]) to a Firestore Value
at Function.encodeValue (...\functions\node_modules\@google-cloud\firestore\src\document.js:772:11
Run Code Online (Sandbox Code Playgroud)
那么如何使用firestore admin nodejs sdk设置服务器时间戳?
node.js firebase google-cloud-functions firebase-admin google-cloud-firestore
我试图使用Firebase云功能将聊天室的ID添加到数组字段中的用户文档.我似乎无法弄清楚写入数组字段类型的方法.这是我的云功能
exports.updateMessages = functions.firestore.document('messages/{messageId}/conversation/{msgkey}').onCreate( (event) => {
console.log('function started');
const messagePayload = event.data.data();
const userA = messagePayload.userA;
const userB = messagePayload.userB;
return admin.firestore().doc(`users/${userA}/chats`).add({ event.params.messageId }).then( () => {
});
});
Run Code Online (Sandbox Code Playgroud)
这是我的数据库看起来的方式
任何提示非常感谢,我是firestore的新手.
node.js firebase google-cloud-functions firebase-admin google-cloud-firestore
我正在设计一个基于VueJs(用于UI)+ NodeJs(用于后端,将在Google Cloud Platform中运行)+ Firestore(用于auth +数据库)的应用程序(我们称之为TodoList应用程序).
我已经浏览了Google的大量文档(有时是多余的!)来实现应该有用的东西,但我不确定它是否符合生产要求.
情况:
我在Firestore数据库上设置了一些安全规则:
service cloud.firestore {
match /databases/{database}/documents {
match /users/{userId}/{document=**} {
allow read, write: if request.auth.uid == userId;
}
}
}
Run Code Online (Sandbox Code Playgroud)
这样我就不希望任何记录的用户访问其他用户的数据.
题:
由于Firebase Admin SDK对我的Firestore数据库具有完全权限,因此如何确保不会出现任何安全问题.现在,我只是验证请求中发送的accessToken到我的后端,但......有些东西让我觉得这个错了!
码:
在客户端:
auth.onAuthStateChanged((user) => {
if (user) {
// Save the user credentials
}
}
Run Code Online (Sandbox Code Playgroud)
在服务器端:
// idToken comes from the client app (shown above)
// …Run Code Online (Sandbox Code Playgroud) authentication node.js firebase firebase-admin google-cloud-firestore
我正在使用本教程:https : //firebase.google.com/docs/auth/admin/create-custom-tokens#using_a_service_account_id
创建一个 node.js 函数(部署到谷歌云函数)来验证我的用户。功能超级简单:
const admin = require('firebase-admin');
admin.initializeApp({
serviceAccountId: 'authenticator@igibo-b0b27.iam.gserviceaccount.com'
});
exports.authenticate = (req, res) => {
let pass;
let uid;
if (req.query) {
if (req.query.v == 3) {
pass = req.query.p;
uid = req.query.u;
}
admin.auth().createCustomToken(uid)
.then(function(customToken) {
res.status(200).send(customToken);
return customToken;
})
.catch(function(error) {
console.error("Error creating custom token:" + JSON.stringify(error));
res.status(400).send(error);
});
} else {
console.error("EMPTY to authentication");
res.end();
}
};
Run Code Online (Sandbox Code Playgroud)
但我收到了这个烦人的错误:
{"code":"auth/insufficient-permission","message":"Permission iam.serviceAccounts.signBlob is required to perform this operation on service account projects/-/serviceAccounts/authenticator@igibo-b0b27.iam.gserviceaccount.com.; Please …Run Code Online (Sandbox Code Playgroud) 我正在玩新的 firebase auth 模拟器(在节点管理 SDK 上),并且做了一些测试,如果我在每次测试之间手动删除创建的用户,这些测试可以完美运行,但我似乎无法自动删除它们?
我已经在我的 beforeEach() 中使用了此处定义的端点,但是我从响应调用中得到了“响应代码 401,未经授权”?
端点:删除: http://localhost:9099/emulator/v1/projects/{project-id}/accounts
我只是尝试使用 Postman 发送电话,它的回复如下:
{
"error": {
"code": 401,
"message": "Request is missing required authentication credential. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.",
"errors": [
{
"message": "Login Required.",
"domain": "global",
"reason": "required",
"location": "Authorization",
"locationType": "header"
}
],
"status": "UNAUTHENTICATED"
}
}
Run Code Online (Sandbox Code Playgroud)
除了向网络应用程序添加一个谷歌按钮之外,错误中的 URL 似乎没有给我太多帮助,这使我指向创建一个 OAuth2 网络帐户。我在现有的 localhost:9099 中输入了 localhost:9099,但不知道应该在哪里使用客户端 ID 和客户端密码?如果它们是我应该使用的。
我知道我需要某种用于删除调用的 Authorization 标头,但我只是不知道应该在该标头中放入什么,或者如何放入。
感谢您对此有任何了解。
编辑:我现在尝试了以下授权标头:
“行政”
""(空字符串) …
我的项目中有多个 firestore 数据库。数据库是使用命令行创建的,我可以按照此处的说明在 Firestore 数据库预览中看到它:https: //cloud.google.com/blog/products/databases/manage-multiple-firestore-databases-in-a -项目
我能够连接到默认数据库,但在连接到其他命名数据库时遇到问题。我希望能够更新/删除其他数据库中的数据。
我正在尝试使用最新的 firebase-admin sdk (11.10.1) 连接到数据库,该 SDK 支持多个命名数据库( https://firebase.google.com/support/release-notes/admin/node )
我想使用函数getFirestore(databaseId)或getFirestore(app, databaseId)
(https://firebase.google.com/docs/reference/admin/node/firebase-admin.firestore),但当我尝试保存数据时出现以下错误:
错误:3 INVALID_ARGUMENT:请求是针对数据库“projects/testproject/databases/testdb”,但试图访问数据库“projects/testproject/databases/(default)”
我的代码如下所示:
const { getFirestore } = require('firebase-admin/firestore');
const {
initializeApp,
applicationDefault,
} = require('firebase-admin/app');
const app = initializeApp({
credential: applicationDefault(),
});
const db = getFirestore();
const otherFirestore = getFirestore('testdb');
const saveData = async (col, doc, data) => {
await otherFirestore
.collection(col)
.doc(doc)
.set(data, { merge: true });
};
Run Code Online (Sandbox Code Playgroud)
如果我使用 db 而不是 otherFirestore,数据将保存到我的默认数据库中。我也尝试过这样做,const …
javascript node.js firebase firebase-admin google-cloud-firestore