I want to create user profile in realtime database after google login in my android app.
So, I have tried this code in cloud function to do it.
const functions = require(‘firebase-functions’);
const admin = require(‘firebase-admin’);
admin.initializeApp(functions.config().firebase);
exports.AddAccount = functions.auth.user().onCreate(event => {
const user = event.data;
var userObject = {
displayName : user.displayName,
email : user.email,
photoUrl : user.photoURL,
createdOn : user.metadata.createdAt
};
admin.database().ref('users/' + user.uid).set(userObject);
});
after deploying this code i tested in my app.
and it is showing error.
TypeError: Cannot read property 'displayName' of undefined
at exports.AddAccount.functions.auth.user.onCreate.event (/srv/index.js:10:22)
at cloudFunction (/srv/node_modules/firebase-functions/lib/cloud-functions.js:131:23)
at /worker/worker.js:825:24
at <anonymous>
at process._tickDomainCallback (internal/process/next_tick.js:229:7)
please help me to fix this error