[英]Firebase module requires an older version of node while deploying the 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 令牌从您的客户端发送到您的函数,使用 Admin SDK 对其进行验证,然后代表用户执行一些操作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.