javascript - Firebase 模块在部署功能时需要旧版本的 Node

标签 javascript node.js firebase firebase-authentication google-cloud-functions

我想创建一个使用“firebase”模块(而不是“firebase-functions”)的云函数 当我使用甚至只导入它时,npm 会抛出错误:

Error: Error parsing triggers: Failed to load gRPC binary module because it was not installed for the current system
Expected directory: node-v64-darwin-x64-unknown
Found: [node-v79-darwin-x64-unknown]
This problem can often be fixed by running "npm rebuild" on the current system
Original error: Cannot find module '/Users/rame/functions/node_modules/grpc/src/node/extension_binary/node-v64-darwin-x64-unknown/grpc_node.node'
1) If you want to compile the package/file into executable, please pay attention to compilation warnings and specify a literal in 'require' call. 2) If you don't want to compile the package/file into executable and want to 'require' it from filesystem (likely plugin), specify an absolute path in 'require' call using process.cwd() or process.execPath

这是我在类型脚本上的代码:

 import * as functions from 'firebase-functions';
 import admin = require('firebase-admin');
//the cause of an error     
import * as firebase from 'firebase';
    admin.initializeApp()

    export const getProfilePicture = functions.https.onRequest((request, response) => {
//also there
        const uid = firebase.auth().currentUser?.getIdToken

        const promise = admin.storage().bucket().file('usersPfp/' + uid).getSignedUrl({
            action: 'read',
            expires: '03-09.2441'
        })

        const p2 = promise.then(GetSignedUrlResponse => {
            const data = GetSignedUrlResponse[0]
            return response.send({"data": data})
        })

        p2.catch(error =>{
            console.log(error)
            return response.status(500).send({"error": error})
        })
    })

如何解决这个问题?

最佳答案

您正在做的事情不受支持。不支持在 Cloud Functions 等后端环境中使用 Firebase 身份验证 JavaScript 客户端库。

当前用户的想法:

firebase.auth().currentUser

仅在用户登录的客户端应用程序中有意义。后端不知道它。

您可以做的是将用户的 ID token 从您的客户端发送到您的函数,然后使用 Admin SDK verify it ,然后代表用户执行一些操作。

关于javascript - Firebase 模块在部署功能时需要旧版本的 Node ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59845983/

相关文章:

javascript - Google Firestore - 如何在一次往返中通过多个 ID 获取多个文档?

java - 如何使用 RecyclerView 显示空 View ?

javascript - 查询 : link title attribute unchange

javascript - 自动播放用 javascript 创建的 html 音频

javascript - 为什么我必须在类中使用 foo() 而不是函数 foo() ?

ruby-on-rails - Grunticon 和 TravisCI

javascript - Jquery 在悬停时显示文本 - Looped Item

javascript - 如何在不使用模板的情况下插入变量?

java - 与 Firebase 安装服务器 API 通信时出现 Android 错误

javascript - 我有一个带有数据属性的 JSON 文件,其中包含包含有关冠军信息的对象。如何获得具有特定KEY属性的冠军?