AngularUniversal和FirebaseAppCheck的集成
创始人
2024-10-29 21:00:39
0
  1. 首先在 Angular 项目中安装 Firebase 和 Firebase App Check:
npm install firebase @angular/fire firebase/app-check
  1. 在 app.module.ts 中引入 Firebase 和 Firebase App Check 模块,并在 NgModule 的 imports 中注入:
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { AngularFireModule } from '@angular/fire';
import { AngularFireAuthModule } from '@angular/fire/auth';
import { AngularFireDatabaseModule } from '@angular/fire/database';
import { AngularFireFunctionsModule } from '@angular/fire/functions';
import { FirebaseAppCheckModule, FirebaseAppCheckProvider } from '@firebase/app-check';
import { environment } from '../environments/environment';

@NgModule({
  imports: [
    BrowserModule,
    AngularFireModule.initializeApp(environment.firebaseConfig),
    AngularFireAuthModule,
    AngularFireDatabaseModule,
    AngularFireFunctionsModule,
    FirebaseAppCheckModule,
    // 配置 App Check 开发者密钥
    FirebaseAppCheckProvider.forRoot({
      // Replace with your own App Check key pair.
      provider: new firebase.appcheck.RecaptchaVerifier('reCAPTCHA_site_key')
    })
  ],
})
export class AppModule {}
  1. 然后在 App 基本组件中启动 Firebase App Check:
import { Component, OnInit } from '@angular/core';
import firebase from 'firebase/app';
import { FirebaseAppCheck } from '@firebase/app-check';

@Component({
  selector: 'app-root',
  template: `
    
  `
})
export class AppComponent implements OnInit {
  constructor(
    private readonly appCheck: FirebaseAppCheck
  ) {}

  ngOnInit() {
    this.appCheck.activate()
      .catch(error => console.error(error));
  }
}
  1. 在服务端渲染 Angular 应用之前,需要通过另外一个 Firebase Cloud Functions 云函数来获取客户端所需的 App Check Token。以下是一个 Cloud Functions 的示例代码:
const functions = require("firebase-functions");
const admin = require("firebase-admin");
const playwright = require("playwright-core");

admin.initializeApp();

const serviceAccount = require("./serviceAccountKey.json");

const appCheckSettings = {
  app

相关内容

热门资讯

透视系统!aapoker透视插... 透视系统!aapoker透视插件下载,wepoker辅助器怎么用,玩家必看分享(有挂详情);透视系统...
透视中牌率!aapoker可以... 《透视中牌率!aapoker可以开挂吗,aapoker怎么提高中牌率,曝光教程(一直存在有挂)》 a...
透视工具!wpk透视脚本链接,... 透视工具!wpk透视脚本链接,wpk有脚本吗,玩家必备教程(有挂规律)1、每个玩家都可以进行使用,快...
透视肯定!hhpoker辅助下... 1、透视肯定!hhpoker辅助下载,hhpoker是真的假的,爆料教程(总是真的有挂)。2、hhp...
透视透视!wepoker透视脚... 透视透视!wepoker透视脚本苹果版,wepoker辅助器下载,发现一款(有挂黑科技)1、wepo...
透视私人局!wepoker作弊... 透视私人局!wepoker作弊辅助,aapoker透视脚本,教你攻略(原本真的有挂);科技安装教程;...
透视好友!aapoker透视脚... 透视好友!aapoker透视脚本下载,wepoker透视脚本网页,一秒答解(有挂详情)1、每一步都需...
透视好牌!红龙poker辅助,... 透视好牌!红龙poker辅助,wepoker辅助器软件下载,攻略教程(固有真的是有挂);原来确实真的...
透视科技!wpk辅助工具下载,... 透视科技!wpk辅助工具下载,hhpoker透视脚本,热点推荐(有挂辅助挂)1、构建自己的微扑克辅助...
透视数据!wepoker透视版... 透视数据!wepoker透视版下载,hhpoker辅助挂,2025新版总结(本然是有挂);亲,其实确...