How to authenticate escaped email-based user accounts in Firebase?

前端 未结 1 987
难免孤独
难免孤独 2021-01-07 15:11

I am using email/password auth option of Firebase Simple Login.
I store my users\' data with escaped emails as keys, where \'.\' characters have been replaced with \',\'

1条回答
  •  再見小時候
    2021-01-07 16:15

    Update:

    If you're using Firebase Simple Login email / password authentication, it is recommended that you key users based upon the uid field, which will not change and is unique across all users of your Firebase, whether they are authenticating via email / password, Facebook, Google, etc.

    Prior versions of Firebase authentication (i.e. Firebase Simple Login) put an email address in the security rules auth variable, but this was removed because (1) not all users will have email addresses, (2) users may have multiple email addresses, and (3) email addresses can change. As a result, they're not ideal for indexes in Firebase.


    Original Answer:

    However, if you'd rather key your data based upon e-mail address, you can use the .replace() method in security rules to simply replace the periods with commas directly in your security rules. For example:

    ".read": "root.child('users').child(auth.email.replace('.', ',')).exists()"
    

    See https://www.firebase.com/docs/security/string/replace.html for more details.

    0 讨论(0)
提交回复
热议问题