Reputation: 51
i want to add user details in firestore when new user signs up but i m getting this error in console about "Undefined object"
function:
exports.storeUserData = functions.auth.user().onCreate(event =>{
const user = event.data;
var db_uid_user = db_firestore.collection('users').doc(user.uid).set({
'name' : user.displayName,
'email': user.email,
'phoneNumber': user.phoneNumber,
'photoUrl': user.photoURL
});
console.log('User Add (uid)',user.uid);
});
ERROR:
Error: Cannot encode type ([object Undefined]) to a Firestore Value
at Function.encodeValue (/user_code/node_modules/firebase-admin/node_modules/@google-cloud/firestore/src/document.js:658:11)
at Function.encodeFields (/user_code/node_modules/firebase-admin/node_modules/@google-cloud/firestore/src/document.js:530:36)
at WriteBatch.set (/user_code/node_modules/firebase-admin/node_modules/@google-cloud/firestore/src/write-batch.js:254:35)
at DocumentReference.set (/user_code/node_modules/firebase-admin/node_modules/@google-cloud/firestore/src/reference.js:416:8)
at exports.storeUserData.functions.auth.user.onCreate.event (/user_code/index.js:15:71)
at Object.<anonymous> (/user_code/node_modules/firebase-functions/lib/cloud-functions.js:59:27)
at next (native)
at /user_code/node_modules/firebase-functions/lib/cloud-functions.js:28:71
at __awaiter (/user_code/node_modules/firebase-functions/lib/cloud-functions.js:24:12)
at cloudFunction (/user_code/node_modules/firebase-functions/lib/cloud-functions.js:53:36)
Upvotes: 3
Views: 1456
Reputation: 51
So, i forgot that details that user object contain is limited with what kind of Auth your using.
For example: if you are using Email and password , your user object will have only email,password,uid.
hence
'name' : user.displayName, //invalid undefined object
'email': user.email, //valid
'phoneNumber': user.phoneNumber, //invalid
'photoUrl': user.photoURL //invalid
Upvotes: 2