Firebase 可以不用中间层直接连接到Angular吗?

Can Firebase be connected to Angular directly without any intermediate layer?

在一些教程中,讲师说前端不应该直接与您的数据库对话。对于 Angular 和 Firebase,我们必须在 angular 应用程序中提供我们的 firebase 凭据。如果您在 firebase 中将写入和读取的规则都设置为 true,我同意它是不安全的。我知道有一个中间层 (RESTful API) 很好,如果您不需要从数据库进行实时更新。

如果我想在我的 angular 应用程序中具有实时功能,

  1. 直接从 angular 应用程序连接 firebase 可以吗?
  2. 是否有任何其他方法可以使这种实时更新起作用?

Firebase 是一个移动和网络开发平台。尽管 firebase 听起来只是一个数据库,但它不仅仅是一个数据库。它是后端即服务。当您与 firebase 通信时,实际上您不仅在与数据库通信,而且还在与 REST API.

通信

关于您的第一个问题可以直接从 angular 应用程序连接 firebase 吗?。 将您的 Angular 应用程序直接连接到 Firebase 是完全正确的,因为它不仅实时获取数据,而且还利用了 firebase 已经缓存 的数据。

关于你的第二个问题有没有其他方法可以让这个实时更新起作用?。 不,如果您想实时更新,您必须将您的应用程序直接连接到 Firebase。

In some tutorials, the instructor says that the Front end should not talk to your database directly.

这里的讲师很可能在谈论传统数据库,实际上他们的安全模型通常与允许最终用户直接访问不匹配。对于此类数据库,通常会在最终用户应用程序和数据库之间设置一个服务器,即所谓的三层架构,这样您就可以在该服务器中控制用户可以访问哪些数据。

然而,Firebase 的数据库(其实时数据库和 Cloud Firestore)是专门为允许最终用户直接访问而创建的。它们与 Firebase Authentication to allow identifying those users, and then have a built-in server-side security rules language that allows you to control what data each user an access. For example, you could say that each user can only access the data that they created themselves.

紧密集成

we have to provide our firebase credentials in our angular app

您指的很可能是 Firebase 的配置数据。 不是凭据,而只是允许 Firebase SDK 在 Google 的服务器上找到您的项目的值。参见