5

I want to restrict the Firebase Authentication only by ne mail domain name, to make this mail access to my application :

[email protected]

I did this in the database side of firebase

{
  "rules": {
    ".read": "auth.token.email.endsWith('@exemple.fr')",
    ".write": "auth.token.email.endsWith('@exemple.fr')"
  }
}

I think i'm doing something wrong, thank you for your help.

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
Taieb
  • 920
  • 3
  • 16
  • 37

2 Answers2

2

Try this

{
  "rules": {
    ".read": "auth.token.email.matches(/.*@exemple.fr$/)",
    ".write": "auth.token.email.matches(/.*@exemple.fr$/)"
   }
}
Niraj Niroula
  • 2,376
  • 1
  • 17
  • 36
0

this works for me and I am able to restrict logged in Google user to my org domain

rules_version = '2';
service cloud.firestore {
  match /databases/{database}/documents {
    match /{document=**} {
      allow read, write: if request.auth.token.email.matches('.*@domain[.]com');
    }
  }
}
HimalayanCoder
  • 9,630
  • 6
  • 59
  • 60