Firebase onCreate trigger: can't get authType other than UNAUTHENTICATED

六月ゝ 毕业季﹏ 提交于 2019-12-24 09:59:12

问题


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);
    });

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);
    ...
})

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'
    }
}

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

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.


回答1:


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



来源:https://stackoverflow.com/questions/51565780/firebase-oncreate-trigger-cant-get-authtype-other-than-unauthenticated

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!