Firebase onCreate触发器:无法获得除UNAUTHENTICATED之外的authType [英] Firebase onCreate trigger: can't get authType other than UNAUTHENTICATED

查看:52
本文介绍了Firebase onCreate触发器:无法获得除UNAUTHENTICATED之外的authType的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用具有以下规则的Firebase实时数据库:

Using a Firebase Realtime Database with these rules:

{
    "rules": {
        "messages": {
            ".read": "auth != null",
            ".write": "auth != null"
        }
    }
}

而且,将此触发器定义为:

And, having this trigger defined as:

exports.localOnCreate = functions.database.ref('/messages/{messageId}')
    .onCreate((snap, context) => {
        console.log(context);
    });

当我在测试网站(通过Google验证)上运行该程序时:

When I run this on the test website (authenticated via Google):

firebase.database().ref('/messages').push().set({
    'hi': 'from-web'
}).then( function(result) {
    console.log(result);
    ...
})

我在Firebase控制台功能日志中看到了这一点:

I see this in the Firebase Console Functions Log:

{
    eventId: '............',
    timestamp: '2018-07-27T20:51:50.943Z',
    eventType: 'google.firebase.database.ref.create',
    resource: {
        service: 'firebaseio.com',
        name: 'projects/_/instances/..../refs/messages/-LISVklGLfbcfrFvnylZ'
    },
    authType: 'UNAUTHENTICATED',
    auth: null,
    params: {
        messageId: '-LISVklGLfbcfrFvnylZ'
    }
}

如果我在Web应用程序中通过了身份验证,为什么在触发器上下文"(第二个)参数中得到 authType:'UNAUTHENTICATED' auth:null ?

If I am authenticated in the webapp, why am I getting authType: 'UNAUTHENTICATED', and auth: null, in the trigger "context" (second) argument?

而且,正如我在 CloudFunction参考中看到的那样,函数应该只接收一个参数,即事件对象,但似乎不是实时数据库触发器,也没有根据我的测试.最后的冲突使我完全困惑.任何澄清将不胜感激.

And, as I see in CloudFunction reference, this function should receive only one argument, an Event object, but it seems it's not the case as seen in Realtime Database triggers, nor according to my tests. This last conflict got me completely confused. Any clarification will be greatly appreciated.

推荐答案

@RodrigoMata和@claytronicon,这是一个错误.我创建了一个github问题,他们推出了新版本v2.0.4,其中包含针对RTDB事件的authType的修复程序. https://github.com/firebase/firebase-functions/pull/304

Hey @RodrigoMata and @claytronicon, this was a bug. I created a github issue and they pushed out a new release v2.0.4 that contains a fix for authType from RTDB events. https://github.com/firebase/firebase-functions/pull/304

这篇关于Firebase onCreate触发器:无法获得除UNAUTHENTICATED之外的authType的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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