Firebase函数context.auth和context.authType未定义 [英] Firebase function context.auth and context.authType undefined

查看:85
本文介绍了Firebase函数context.auth和context.authType未定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在深入研究Firebase功能(服务器端),并且无法从功能内部获取身份验证信息.以最简单的形式,我即将部署到Firebase函数的index.ts看起来像这样:

I am diving into Firebase functions (server-side), and having trouble grabbing the authentication information from within the function. In it's simplest form, my index.ts that is getting deployed to Firebase functions looks like this :

import * as functions from 'firebase-functions';
import * as admin from 'firebase-admin';

admin.initializeApp();
export const createOrganization = functions.firestore.document("Organizations/{organizationId}").
    onCreate((snap, context) => {
      console.log(context)
});

我从Firebase的日志中可以看到确实调用了该函数,并且所记录的上下文看起来像这样:

I can see from Firebase's logging that this function is indeed getting called, and the context that gets logged looks something like this :

{ eventId: 'XXXXX-XXXX-XXXX',
  timestamp: '2018-04-13T21:37:33.349247Z',
  eventType: 'google.firestore.document.write',
  resource: 
  { service: 'firestore.googleapis.com',
     name: 'projects/XXXX/databases/(default)/documents/Organizations/XXXXXXXXXXXX'
  },
  params: { organizationId: 'XXXXXXXXXXXX' } 
}

我希望从文档中可以看出,上下文参数还将包含名为"authType"和"auth"的属性,这些属性包含有关发出请求的用户的信息.但是,尝试各种方法后,context.authType和context.auth始终是未定义的.

I would expect from the documentation that the context parameter would also include properties called "authType" and "auth" that contain information about the user who is making the request. However, after trying all sorts of things, context.authType and context.auth are always undefined.

我已经作为授权用户和未经授权的用户尝试了此操作,而没有进行任何更改.

I have tried this both as an authorized user and unauthorized user with no changes.

弄清楚为什么未填充context.authType和context.auth的任何帮助都会非常有帮助,谢谢!

Any help figuring out why context.authType and context.auth are not populated would be really helpful, thanks!

推荐答案

仅针对为每个触发事件向Cloud Functions提供身份验证信息的Firebase产品提供身份验证信息.当前,只有实时数据库支持此功能. Firestore支持正在开发中.从理论上讲,云存储也可以提供支持.

Auth information is only given for Firebase products that provide auth information to Cloud Functions for each triggered event. Currently, only Realtime Database supports this. Firestore support is being worked on. In theory, Cloud Storage could provide support as well.

这是不一致的,因为Cloud Functions for Firebase中的每个事件提供程序都是由不同的团队驱动的,每个团队都有不同的实现和优先级.

It's inconsistent because each event provider in Cloud Functions for Firebase is driven by different teams, each with different implementations and priorities.

这篇关于Firebase函数context.auth和context.authType未定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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