Version 1.0.0 of the Firebase SDK for Cloud Functions introduces some important changes in the API. The primary change, a replacement of event.data format with data and context parameters, affects all asynchronous (non-HTTP) functions. The updated SDK can also be used with firebase-functions-test, a brand new unit testing companion SDK. See Unit Testing Functions for more information.
exports.dbWrite = functions.database.ref('/path/with/{id}').onWrite((data, context) => {
const authVar = context.auth; // Auth information for the user.
const authType = context.authType; // Permissions level for the user.
const pathId = context.params.id; // The ID in the Path.
const eventId = context.eventId; // A unique event ID.
const timestamp = context.timestamp; // The timestamp at which the event happened.
const eventType = context.eventType; // The type of the event that triggered this function.
const resource = context.resource; // The resource which triggered the event.
// ...
});
Before (<= v0.9.1)
const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);
Now (>= v1.0.0)
const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp();
functions.config().firebase removed
functions.config().firebase has been removed. If you'd like to access the config values from your Firebase project, use process.env.FIREBASE_CONFIG instead:
let firebaseConfig = JSON.parse(process.env.FIREBASE_CONFIG);
/* { databaseURL: 'https://databaseName.firebaseio.com',
storageBucket: 'projectId.appspot.com',
projectId: 'projectId' }
*/
references:
https://firebase.google.com/docs/functions/beta-v1-diff#realtime-database
exports.dbWrite = functions.database.ref('/path/with/{id}').onWrite((data, context) => {
const authVar = context.auth; // Auth information for the user.
const authType = context.authType; // Permissions level for the user.
const pathId = context.params.id; // The ID in the Path.
const eventId = context.eventId; // A unique event ID.
const timestamp = context.timestamp; // The timestamp at which the event happened.
const eventType = context.eventType; // The type of the event that triggered this function.
const resource = context.resource; // The resource which triggered the event.
// ...
});
Before (<= v0.9.1)
const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);
Now (>= v1.0.0)
const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp();
functions.config().firebase removed
functions.config().firebase has been removed. If you'd like to access the config values from your Firebase project, use process.env.FIREBASE_CONFIG instead:
let firebaseConfig = JSON.parse(process.env.FIREBASE_CONFIG);
/* { databaseURL: 'https://databaseName.firebaseio.com',
storageBucket: 'projectId.appspot.com',
projectId: 'projectId' }
*/
references:
https://firebase.google.com/docs/functions/beta-v1-diff#realtime-database
No comments:
Post a Comment