0
votes

I want to create default values in firebase realtime database when someone login to my application. And i have deployed this code through vb code to cloud function to do this job.

const functions = require('firebase-functions');
const admin = require('firebase-admin');

admin.initializeApp(functions.config().firebase);

exports.defaultaccountparams = functions.auth.user().onCreate(user => {
    const userObject = {
        name : user.displayName,
        email : user.email,
        profile_picture : user.photoURL,
        createdOn : user.metadata.creationTime || null,
        matches_played : 0,
        BC_won : 0,
        total_kills : 0,
        matches_won : 0,
        BC: 0,
        joined_matches : 0,
        };

    admin.database().ref('users/' + user.uid).set(userObject);
  });

But this function is not creating values and in function log there is not any error about this function. Please help me to solve it.

1

1 Answers

0
votes

With Cloud Functions auth triggers, you need to return a promise that resolves only after all the asynchronous work is complete. This is not optional, and is the only way that you can tell Cloud Functions when it's safe to clean up and terminate the function. set() returns a promise, so you can return that directly:

return admin.database().ref('users/' + user.uid).set(userObject);