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)
});
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' }
}
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.
Any help figuring out why context.authType and context.auth are not populated would be really helpful, thanks!
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…