Uncaught TypeError: os.platform is not a function at credential-internal.js:38:20

huangapple go评论71阅读模式
英文:

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.

Uncaught TypeError: os.platform is not a function at credential-internal.js:38:20

When ever i do console.log(admin) or try to use anything imported from 'firebase-admin',
Im getting weired errors.

Uncaught TypeError: os.platform is not a function at credential-internal.js:38:20

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.

huangapple
  • 本文由 发表于 2023年5月30日 00:04:50
  • 转载请务必保留本文链接:https://go.coder-hub.com/76358783.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定