nouhau icon indicating copy to clipboard operation
nouhau copied to clipboard

FirestoreでG Suiteのドメイン指定のセキュリティルールを設定する

Open sinmetal opened this issue 6 years ago • 2 comments

WHAT

Firebase Auth for Googleを利用してログインし、Firestoreでドメイン指定を行いたい!

WHY

gcpug.jp アカウント限定みたいなことをしたい

sinmetal avatar Jul 09 '18 09:07 sinmetal

以下のような感じで、 request.email を見てあげればよいっぽい

service cloud.firestore {
  match /databases/{database}/documents {
    match /{document=**} {
      allow read, write: if false;
    }
    match /users/{userId} {
      allow create,delete,update: if request.auth.uid == userId && request.auth.token.email.matches('.*@gcpug[.]jp');
    }
  }
}

sinmetal avatar Jul 09 '18 09:07 sinmetal

カスタムAuthでがんばるという手もある https://github.com/firebase/functions-samples/tree/master/instagram-auth

sinmetal avatar Jul 09 '18 09:07 sinmetal