1

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.

6
  • What exactly is the value of accessToken? Commented Apr 24, 2020 at 15:09
  • Contains a JWT token
    – Pere
    Commented Apr 24, 2020 at 15:16
  • And the exact value is...? Commented Apr 24, 2020 at 15:20
  • The value is this one (some sensitive charater altered) pastebin.com/s4aYtcTP
    – Pere
    Commented Apr 24, 2020 at 15:38
  • The error is suggesting that something is not right with Realtime Database, so you have some debugging to do with how you call its APIs. This doesn't have anything to do with auth. Commented Apr 24, 2020 at 15:40

0

Your Answer

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