I am deploying a cloud function in Firebase that acts as a OAuth2 middleware, handling the authorization and getting the token. After getting the access token and user details I want to store the token and user details in the database and also update or create the user. The code is from this example. But I'm always getting the same error message from function logs:
TypeError: obj.hasOwnProperty is not a function
at each (/srv/node_modules/@firebase/database/dist/index.node.cjs.js:553:17)
at validateFirebaseData (/srv/node_modules/@firebase/database/dist/index.node.cjs.js:1511:9)
at /srv/node_modules/@firebase/database/dist/index.node.cjs.js:1528:13
at each (/srv/node_modules/@firebase/database/dist/index.node.cjs.js:554:13)
at validateFirebaseData (/srv/node_modules/@firebase/database/dist/index.node.cjs.js:1511:9)
at /srv/node_modules/@firebase/database/dist/index.node.cjs.js:1528:13
at each (/srv/node_modules/@firebase/database/dist/index.node.cjs.js:554:13)
at validateFirebaseData (/srv/node_modules/@firebase/database/dist/index.node.cjs.js:1511:9)
at /srv/node_modules/@firebase/database/dist/index.node.cjs.js:1528:13
at each (/srv/node_modules/@firebase/database/dist/index.node.cjs.js:554:13)
Below is the function for creating a user
async function createFirebaseAccount(uid, displayName, email, accessToken) {
const databaseTask = admin.database().ref(`/idpAccessToken/${uid}`).set(accessToken);
const userCreationTask = admin.auth().updateUser(uid, {
displayName: displayName,
email: email,
emailVerified: true,
}).catch((error) => {
if (error.code === 'auth/user-not-found') {
return admin.auth().createUser({
uid: uid,
displayName: displayName,
email: email,
emailVerified: true,
});
}
throw error;
});
// execution stops here, when resolving this tasks
await Promise.all([userCreationTask, databaseTask]);
const token = await admin.auth().createCustomToken(uid);
console.log('Created Custom token for UID "', uid, '" Token:', token);
return token;
}
The variables uid, displayName, email and token are a plain text string in all four cases. The token returned from this function is later returned to the calling client using jsonp
. I don't understand where this error comes from.