小编mhu*_*ini的帖子

firebase - 从可调用的云函数访问数据库时应用检查失败

我最近为我的 firebase 应用启用了App Check,并在我的云功能和数据库上强制执行。云函数工作流运行正常。但是,我无法再从该函数访问数据库。我的可调用函数的最小版本如下所示:

exports.myFunc = functions.https.onCall(async (data, context) => {
  const adminApp = admin.initializeApp();
  const ref = adminApp.database().ref('some-node');
  
  if (context.app === undefined) {
    throw new functions.https.HttpsError(
      'failed-precondition',
      'The function must be called from an App Check verified app.',
    );
  }

  try {
    return (await ref.orderByKey().equalTo('foo').get()).exists()
  } catch(exc) {
    console.error(exc);
  }
});
Run Code Online (Sandbox Code Playgroud)

这曾经在 App Check 之前工作,但现在它失败了,我在日志中看到了这一点:

@firebase/database:FIREBASE 警告:无效的 appcheck 令牌(https://my-project-default-rtdb.firebaseio.com/)错误:错误:客户端离线。

似乎我需要做一些额外的事情才能让admin应用程序将 App Check 验证传递给数据库,但我还没有找到任何关于此的文档。我还尝试使用应用程序实例functions.app.admin而不是初始化一个新的应用程序实例,但这没有帮助。

我有最新版本的软件包:

"firebase-admin": "^9.10.0"
"firebase-functions": "^3.14.1"
Run Code Online (Sandbox Code Playgroud)

node.js firebase-realtime-database google-cloud-functions firebase-admin firebase-app-check

6
推荐指数
1
解决办法
534
查看次数

Angular2-ContentChild查询找不到嵌套组件

我正在尝试建立一个Angular2组件,该组件自动聚焦通过内容投影插入的输入元素。

我正在使用的解决方案基于此答案。我还有一个额外的要求,即输入元素可能嵌套在另一个组件中。但是,我发现该ContentChild查询无法检测埋在ng-content标签内部的元素。

@Component({
  selector: 'inner-feature',
  template: "<input auto-focus>",
  directives: [AutoFocus]
})
export class InnerFeature { }

@Component({
  selector: 'feature',
  template: `
    <div [class.hide]="!show">
      <ng-content></ng-content>
    </div>
  `
})
export class Feature {
  @ContentChild(AutoFocus)
  private _autoFocus: AutoFocus;

  private _show: boolean = false;

  @Input()
  get show() {
    return this._show;
  }
  set show(show: boolean) {
    this._show = show;
    if (show && this._autoFocus) {
      setTimeout(() => this._autoFocus.focus());
    }
  }
}

@Component({
  selector: 'my-app',
  template: `
    <div>
      <button (click)="toggleFeature()">Toggle</button>
      <feature …
Run Code Online (Sandbox Code Playgroud)

typescript angular

5
推荐指数
2
解决办法
4022
查看次数