Tag: firebase

firebasefunction来触发通知

我想创build一个firebase函数,当表中有新的条目时会触发一个通知。 我有包含所有设备令牌的单独的表。 无法弄清楚如何从表中获取每个设备令牌。 这里是我迄今为止写的一些firebase函数的代码片段,但没有运气。 'use strict'; const functions = require('firebase-functions'); const admin = require('firebase-admin'); admin.initializeApp(functions.config().firebase); exports.sendNotificationToAllMembers = functions.database.ref('/chatRoom/{messageNode}').onWrite(event => { const messageInfo = event.params.messageNode; // Get the list of device notification tokens. const getDeviceTokensPromise = admin.database().ref(`/deviceTokens`).once('value'); // Get newly added Message detail const getMovieMessageDetail = admin.database().ref(`/chatRoom/${messageInfo}`).once('value'); return Promise.all([getDeviceTokensPromise, getMovieMessageDetail]).then(results => { const deviceTokensList = results[0]; […]

Firebase child.once在auth.signInWithEmailAndPasswordcallback中超时不一致

我有一个简单的nodejs服务,在AWS EC2(ubuntu)中运行firebase。 我所要做的就是使用Firebase身份validationlogin用户,并在成功login时返回用户信息(附加信息)。 问题是,从用户对象获取用户信息的调用正在超时。 并非所有的时间,这是不一致的,而且总是当我第一次尝试在早上(或几个小时的空闲服务器)。 我从卷发中注意到的,是一天中的第一个要求,花费很长时间才能返回大约30多秒。 (使用免费的Firebase) 你能帮我确定我做错了什么吗? 我该如何解决这个问题? find下面的代码: const auth = firebase.auth(); const users = firebase.database().ref('users'); const db = firebase.database(); /* ..a lot of code in between.. */ let login = function(requestParam, callback) { console.log('userhandler.login called ' + new Date() + ' ' + requestParam.email) auth.signInWithEmailAndPassword(requestParam.email, requestParam.password).catch((error)=>{ console.log("error while signInWithEmailAndPassword " + error); […]

FireStore – TypeError:k.setTimeout不是一个函数

我在React Native应用程序中使用Firebase,并使用Facebook令牌进行身份validation。 它适用于RealTime数据库。 但不是Firestore。 当我调用collection.get,设置或添加我得到这个错误,这是我的处理程序没有捕获,但只是倾倒在控制台。 (node:15795)UnhandledPromiseRejectionWarning:未处理的承诺拒绝(拒绝ID:1):TypeError:k.setTimeout不是函数 我也尝试作为一个独立的脚本运行node t_firebase.js 。 我安装了包 npm install firebase npm install firestore 我使用节点v6.11.4和npm 3.10.10,firestore 1.1.6,firebase 4.5.1 这是脚本: var firebase = require("firebase"); require("firebase/firestore"); var config = { apiKey: "…", authDomain: "….firebaseapp.com", databaseURL: "https://….firebaseio.com", projectId: "…", storageBucket: "…", messagingSenderId: "…" }; firebase.initializeApp(config); testFirebase(); function testFirebase(){ console.log("testFirebase"); token="…"; var credential = firebase.auth.FacebookAuthProvider.credential(token); firebase.auth().signInWithCredential(credential) .then(function(val){testFirestore();}) […]

通过云端function检索Firebase存储图像链接

如何通过云端function检索Firebase中存储的图片的下载链接? 我已经尝试了各种各样的变化,包括下一个: exports.getImgs = functions.https.onRequest((req, res) => { var storage = require('@google-cloud/storage')(); var storageRef = storage.ref; console.log(storageRef); storageRef.child('users/user1/avatar.jpg').getDownloadURL().then(function(url) { }); });

通过电子邮件创build的Firebase-Admin用户显示为匿名

我用一个最小的(名字/电子邮件/密码)表单使用admin sdk。 用提供的电子邮件创build的用户仍然在控制台中匿名显示。 我的代码:(NodeJs) const admin = require('firebase-admin'); const secret = require('./../credentials/server'); admin.initializeApp({ credential: admin.credential.cert(secret), databaseURL: 'url', }); module.exports = (user) => { admin.auth().createUser({ email: user.email, password: user.password, displayName: user.name, }) .then((userRecord) => { // See the UserRecord reference doc for the contents of userRecord. console.log('Successfully created new user:', userRecord.uid); }) .catch((error) => { console.log('Error […]

Firebase:如何以编程方式为类似于`firebase.auth()。currentUser.getIdToken(false)`的特定用户生成一个jwt标记?

我有一个http云端函数,希望在授权标头中传递一个jwt令牌(类似于Will在这个问题中的回答: 如何保护firebase云端functionHTTP端点只允许Firebaseauthentication的用户? )。 这个云function通过函数admin.auth().verifyIdToken(<token>)validation令牌。 在我的客户端代码中,我使用代码firebase.auth().currentUser.getIdToken(false)生成一个包含在上述头部的http请求中的令牌。 我想能够以编程方式给用户的uid生成这个令牌,最好是在Node中,这样我就可以为我的函数编写testing,而无需通过我的web应用程序来获取令牌。 我尝试使用admin.auth().createCustomToken(<uid>)但是不创build可以用admin.auth().verifyIdTokenvalidation的标记。 我也尝试按照本指南https://firebase.google.com/docs/database/rest/auth中的步骤操作,但生成的令牌不是verifyIDToken接受的令牌,尽pipe我可以使用REST调用数据库它(如指南中所述)。

Firebase错误消息/身份validation错误

当使用firebase nodejs sdk时,服务器密钥的位置在哪里? 我收到错误消息/身份validation错误消息:'尝试向FCM服务器进行身份validation时发生错误。 确保用于validation此SDK的凭据具有适当的权限。 但是我的SDK在处理authentication时起作用,所以它绝对是初始化的,而不是消息传递。

从本地运行的云function调用“subscribeToTopic”

我不断收到权限错误… “尝试向FCM服务器进行身份validation时发生错误,请确保用于validation此SDK的凭据具有适当的权限,有关安装说明,请参阅https://firebase.google.com/docs/admin/setup 。 …当我在本地运行调用subscribeToTopic和unsubscribeToTopic的云function。 当我将我的函数部署到firebase时,这个问题不会发生。 我正在使用firebase-admin并在我的云端function中设置firebase … const admin = require('firebase-admin'); admin.initializeApp(functions.config().firebase); authentication问题只发生在调用subscribeToTopic和unsubscribeToTopic 。 从云端函数写入数据库可以正常工作。 我可以通过调用admin.initializeApp通过admin.initializeApp控制台创build的生成的服务帐户json文件)来解决此问题。 任何想法,为什么发生这种情况?

Firebase – NodeJS:用于Google API的OAuth2域范围委派

目标: 此Firebase云端function应使用Cloud API与域范围委派,以便任何用户在Firebase数据库更改时更新一些 G Suitepipe理控制台用户信息。 题: 我应该使用哪个包的方法来获得应用程序的广泛代理权。 firebase : firebase.auth.GoogleAuthProvider() googleapis : google.auth.OAuth2 google-auth-library : new GoogleAuth() 细节: 关于Google Identity Platform ,我并没有把这个问题连接起来,而我却陷入了这一步 。 firebase托pipe的nodejs应用如何将Google API请求的Web和访问令牌放在一起? Firebase项目使用Google云端平台项目 我有… 通过GCP-Console中的API /凭证添加到项目中的service account actor 选中启用G Suite域范围委派框 存储private_key.JSON。 授权API客户端(位于G Suitepipe理控制台中)和服务帐户客户端ID 我应该使用… Firebase :可能会查看Google OAuth2设置的白名单区域 ,和/或使用我从firebase获得的services.json 。 Google API通过googleapis :尽pipe我使用firebase.auth.GoogleAuthProvider()来validation用户,也许可以使用google.auth.OAuth2从GCP获取域范围的委派(如应用程序或计算引擎) Google Auth通过google-auth-library :同样,即使我使用firebase.auth.GoogleAuthProvider()来validation用户,也许使用new GoogleAuth()从GCP获取域范围的委托(如应用程序或计算引擎) 更新 我学过: Google的npm包googleapis不适用于客户端(浏览器)。 我现在正尝试在Firebase云端函数中使用它

将Firestore依赖项和types导入到node.js

我最近在今年的FirebaseSummit会谈后将我的云function更新到了TypeScript 。 我所有的代码看起来相当酷,但我有一些问题,试图恢复types的Firestore API,如QuerySnapshot , DocumentReference … async function getEventsMadeByUser(userId: string): Promise<FirebaseFirestore.DocumentSnapshot[]> { const eventsMadeByUserQuery = await instance.collection('PrivateUserData') .doc(userId).collection(EVENTS) .where('interactionUser', '==', userId).get(); return eventsMadeByUserQuery.docs; } 现在我的IDE(WebStorm)没有获取FirebaseFirestore的types。 这是我的package.json外观: { "name": "functions", "description": "Cloud Functions for Firebase", "dependencies": { "firebase-admin": "^5.4.3", "firebase-functions": "^0.7.2" }, "devDependencies": { "@types/express": "^4.0.37", "typescript": "^2.3.2" }, "scripts": { "build": "tsc", "watch": "tsc […]