【问题标题】:Firebase module requires an older version of node while deploying the functionsFirebase 模块在部署功能时需要旧版本的节点
【发布时间】:2020-01-21 17:05:11
【问题描述】:

我想制作一个使用“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

这是我的 Type 脚本代码:

 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})
        })
    })

如何解决?

【问题讨论】:

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


    【解决方案1】:

    不支持您正在执行的操作。 Firebase 身份验证 JavaScript 客户端库不支持在 Cloud Functions 等后端环境中使用。

    当前用户的想法:

    firebase.auth().currentUser
    

    仅在用户登录的客户端应用中才有意义。这不是后端已知的内容。

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

    【讨论】:

    • 客户端应该如何向后端发送一个IdToken?它没有显示在您发送的示例中
    • 任何你想要的方式。许多人选择使用授权 http 标头。
    • 好吧,但我实际上不知道这些方法中的任何一种:)
    猜你喜欢
    • 2020-06-23
    • 2022-01-03
    • 1970-01-01
    • 1970-01-01
    • 2020-07-09
    • 2021-02-26
    • 1970-01-01
    • 2018-03-31
    • 1970-01-01
    相关资源
    最近更新 更多