0

I making firestore functions and I get this error in log

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

var defaultApp = admin.initializeApp(functions.config().firebase)

const firestore = admin.firestore();
const firebase = admin.database();



module.exports.onUserStatusChange = functions.firestore.document('/status/{userId}').onUpdate((change,context) => {



    const newValue = change.after.data();
    console.log('new value',newValue);
    console.log('change',change);
    console.info('context',context)
    admin.firestore().collection('status')
    .where('state', '==', 'online')
    .onSnapshot(function(snapshot) {
        snapshot.docChanges.forEach(function(change) {
            console.info('change->',change.type)
            if (change.type === 'added') {
                var msg = 'User ' + change.doc.id + ' is online.';
                console.log(msg);
                // ...
            }
            if (change.type === 'removed') {
                var msg = 'User ' + change.doc.id + ' is offline.';
                console.log('removed',msg);
                // ...
            }
        });
    });
    return newValue;

});

I get this error because here I define the firebase in config

    var defaultApp = admin.initializeApp(functions.config().firebase)

and not firestore, but into the web of firebase I create Firestore database. so I'm looking a way to connect my firestore to this file and work with firestore database

1 Answer 1

3

Change this:

var defaultApp = admin.initializeApp(functions.config().firebase)

to this:

var defaultApp = admin.initializeApp();

more info here:

https://firebase.google.com/docs/functions/beta-v1-diff

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.