如何在 Angular 中初始化 Firebase 应用检查 [英] How to initialise Firebase App Check in Angular

查看:27
本文介绍了如何在 Angular 中初始化 Firebase 应用检查的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如何使用 angular 初始化 firebase 应用程序检查.

I was wondering how can i initialise firebase app check using angular.

我正在使用 angular fire,但在使用任何服务之前我不确定如何初始化 firebase 应用程序检查

I am using angular fire but I am not sure how to initalise firebase app check before using any of the services

文档有这个

在您访问任何 Firebase 服务之前,将以下初始化代码添加到您的应用程序中.

Add the following initialization code to your application, before you access any Firebase services.

firebase.initializeApp({
  // Your firebase configuration object
});

const appCheck = firebase.appCheck();
// Pass your reCAPTCHA v3 site key (public key) to activate(). Make sure this
// key is the counterpart to the secret key you set in the Firebase console.
appCheck.activate('abcdefghijklmnopqrstuvwxy-1234567890abcd');

但是这如何在应用模块中完成.目前我像这样导入角火

But how can this be done in app module. Currently i import angular fire like so

@NgModule({
  declarations: [
   ...
  ],
  imports: [
    AngularFireModule.initializeApp(environment.firebaseConfig),
  ],
]

更新:

我知道这可能不是 angular fire 库的一部分,因为新的 firebase app-check 是如何的,但我注意到有一个原生的 firebase 库https://www.npmjs.com/package/@firebase/app-check

I know this is probably not yet part of the angular fire library due to how new firebase app-check is but I have noticed there is a native firebase library https://www.npmjs.com/package/@firebase/app-check

我很高兴使用它(例如,以某种方式覆盖本机 firebase js 对象),只要代码能够在调用任何服务之前将其应用到正确的位置,并且它不会在打字稿中出现编译错误

I am happy for this to be used (e.g. somehow overriding the native firebase js object) as long as the code is able to apply it in the correct location before any services are called and that it gives no compilation errors in typescript

参考我的版本如下:

角度:10.2.5

Firebase:8.6.0

Firebase: 8.6.0

AngularFire:6.1.5

AngularFire: 6.1.5

调试本地主机版本也必须工作

The debug localhost version must also work

推荐答案

这样做:

// firebase-initialization.ts
import firebase from 'firebase/app';
import 'firebase/app-check';

// Environment Config
import { environment } from './path/to/environments';

const app = firebase.initializeApp(environment.firebase);
const appCheck = app.appCheck()
appCheck.activate('');

然后将应用模块中的文件导入为:

Then import the file in the app module as:

import "firebase-initialization"

这篇关于如何在 Angular 中初始化 Firebase 应用检查的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆