我想创建一个使用“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/