Google cloud firestore 结合facebook登录的firebase规则&;正常注册

Google cloud firestore 结合facebook登录的firebase规则&;正常注册,google-cloud-firestore,firebase-security,Google Cloud Firestore,Firebase Security,我需要合并firebase firestore的规则。如果我使用标准方法 rules_version = '2'; service cloud.firestore { match /databases/{database}/documents { match /{document=**} { allow read, write: if request.auth != null; } } } 通常使用用户名、电子邮件和密码注册用户的方法很有效&一切都很完美,一

我需要合并firebase firestore的规则。如果我使用标准方法

rules_version = '2';
service cloud.firestore {
  match /databases/{database}/documents {
    match /{document=**} {
      allow read, write: if request.auth != null;
    }
  }
}
通常使用用户名、电子邮件和密码注册用户的方法很有效&一切都很完美,一切都适合我。 但是facebook登录方法停止工作。很可能是因为用户尚未登录到服务器,但已尝试将数据写入用户集合。因此,我可以在授权用户列表中看到它,但在firestore中,它的电子邮件字段仍然为零。如果我使用允许每个人从互联网上写入数据的标准规则(我知道这是不好的做法)

一切正常。所以我需要以某种方式添加一条规则,允许每个人将数据写入我的用户集合?触发器用于在注册期间创建文档

exports.createAccountDocument = functions.auth.user().onCreate(async user => {
  const { uid, displayName, email } = user
  const username = displayName;
  const profileImageUrl = uid;

const str = username;
const qwery = [];
for (let i = 0; i < str.length; ++i) {
    qwery[i] = str.substring(0, i + 1).replace(/\s/g, "").toLowerCase();
}
  const keywords = qwery;
  const bio = "";
  return await admin
    .firestore()
    .collection("users")
    .doc(uid)
    .set({ bio, keywords, email, profileImageUrl, uid, username })
})

使用Firestore的服务器SDK(包括Firebase Admin SDK)在云函数中运行的代码总是绕过安全规则。无论您在安全规则中写了什么,在onCreate触发器中显示的代码始终能够写入Firestore

安全规则仅适用于从web和移动客户端直接访问。您的规则应该关注由Firebase身份验证控制的访问

exports.createAccountDocument = functions.auth.user().onCreate(async user => {
  const { uid, displayName, email } = user
  const username = displayName;
  const profileImageUrl = uid;

const str = username;
const qwery = [];
for (let i = 0; i < str.length; ++i) {
    qwery[i] = str.substring(0, i + 1).replace(/\s/g, "").toLowerCase();
}
  const keywords = qwery;
  const bio = "";
  return await admin
    .firestore()
    .collection("users")
    .doc(uid)
    .set({ bio, keywords, email, profileImageUrl, uid, username })
})
rules_version = '2';
service cloud.firestore {
  match /databases/{database}/documents {
    match /{document=**} {
      allow read, write: if request.auth != null;
    }
  }
match /users/{document=**} {
      allow read, write: if true ;
    }
}