firebase admin.auth().getUserByProviderUid 不是函数

firebase admin.auth().getUserByProviderUid is not a function

我想在我的 nodeJs 中使用 this question 在我的 firebase 身份验证中由 facebook 提供商用户删除。但不知何故,我收到 getUserByProviderUid 不是函数的错误。我在下面附上了错误消息。

这是代码

exports.deleteUserData = functions.https.onRequest(async (req, 
res) => {
  try {
  const signedRequest = req.body.signed_request;
  console.log('signRewues',signedRequest)
  const userObj = parseSignedRequest(signedRequest, 
  'Facebook secret');
  console.log('User Obj',userObj, userObj.user_id);
  const userRecord = await 
  admin.auth().getUserByProviderUid("facebook.com", 
  userObj.user_id);
  console.log('userRecord',userRecord);
  await admin.auth().deleteUser(userRecord.uid);
  res.json({
    url: "<URL>",
    confirmation_code: "<Code>",
  });
  } catch (e) {
  console.log(e);
  res.status(400).json({
    message: "Bad Request",
  });
  }
});

function base64decode(data) {
   while (data.length % 4 !== 0) {
    data += "=";
   }
   data = data.replace(/-/g, "+").replace(/_/g, "/");
   return Buffer.from(data, "base64").toString("utf-8");
};

function parseSignedRequest(signedRequest, secret) {
   var encoded_data = signedRequest.split(".", 2);
   // decode the data
   var sig = encoded_data[0];
   var json = base64decode(encoded_data[1]);
   var data = JSON.parse(json);
  if (!data.algorithm || data.algorithm.toUpperCase() != "HMAC- 
  SHA256") {
    throw Error(
    "Unknown algorithm: " + data.algorithm + ". Expected HMAC- 
  SHA256"
  );
  }
  var expected_sig = crypto
    .createHmac("sha256", secret)
    .update(encoded_data[1])
    .digest("base64")
    .replace(/\+/g, "-")
    .replace(/\//g, "_")
    .replace("=", "");
  if (sig !== expected_sig) {
    throw Error("Invalid signature: " + sig + ". Expected " + 
    expected_sig);
  }
  return data;
}

在 Admin SDK 的 9.5.0 版本中添加了 getUserByProviderUid()。您必须更新 Admin SDK 才能使用它。尝试升级到最新版本。

npm i firebase-admin@latest