英文:
Uncaught TypeError: os.platform is not a function at credential-internal.js:38:20
问题
I'm creating a reusable library, I'm importing the Firebase Admin SDK into my library and calling my exported function inside my React app.
Whenever I do console.log(admin)
or try to use anything imported from 'firebase-admin', I'm getting weird errors.
Help me out. I am doing it in a correct approach. What I really wanted is to create a reusable library based on the Firebase and Firebase Admin SDKs. My app is built with NX Repo.
Let me know how to fix it or what am I doing wrong?
Thanks in advance.
英文:
I'm creating a reusable library, im importing firebase admin sdk in my lib and calling my exported function inside my react app.
When ever i do console.log(admin)
or try to use anything imported from 'firebase-admin',
Im getting weired errors.
Help me out. I am doing it in a correct approach.
what i really wanted is to create a reusable library based on firebase and firebase-admin sdk. My app is built with NX Repo.
Let me know how to fix it or what am i doing wrong ?
Thanks in advance.
答案1
得分: 2
你不能直接在React应用或任何其他前端框架中直接使用firebase-admin。JavaScript SDK需要一个Node.js后端,因为它用于执行对项目的特权操作,这些操作不应该暴露给前端,因为存在安全风险。
文档中已经相当明确了:
将Firebase Admin SDK添加到您的服务器
Admin SDK是一组服务器库,允许您在特权环境中与Firebase进行交互,执行诸如以下操作的操作:
在Web应用程序中使用Admin SDK的方式是让您的应用调用后端端点以代表用户执行工作。
英文:
You can't use firebase-admin directly in a React app, or any other frontend framework. The JavaScript SDK requires a nodejs backend because it's used to perform privileged operations on your project that would be insecure to expose to your frontend.
The documentation makes this fairly clear:
> Add the Firebase Admin SDK to your server
>
> The Admin SDK is a set of server libraries that lets you interact with Firebase from privileged environments to perform actions like:
The way you're supposed to the the admin SDK in a web application is by having your app invoke a backend endpoint to perform the work on the user's behalf.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论