简体   繁体   中英

Store user data with only Firebase Firestore without auth?

I want to link my game to a database that stores username and high scores, in order to create a leaderboard. A lot of tutorials I watched uses Firebase Authentication, but I want to store only the username without any email signup. Is it possible to only use Firebase Firestore to store user data? It would also be helpful if there is any guide I can use to do so.

Yes you can do that. You need to implement also SharedPreference . SharedPreference will use as to check whether user already logged in or not.

Assume your json look like this:

-user
   -userUid
      -username = USERNAME
      -psw = PSW
      -otherData = ...
   -userUid
      -username = USERNAME2
      -psw = PSW2
      -otherData = ...

From here, you can do a loop and compare each of them if username and psw are correct. Once it is, exit the loop and make it as logged in.

A lot of tutorials I watched uses Firebase Authentication

The tutorials you have watched are using Firebase Authentication because it provides a really useful feature, which is securing the database usingCloud Firestore Security . These rules are enforced on the server, so can't be bypassed by malicious users.

Is it possible to only use Firebase Firestore to store user data?

Yes, it is. If you are not interested to secure your database, you can create a structure that looks like this:

Firestore-root
  |
  --- users (collection)
       |
       --- $username (document)
            |
            --- age: 20
            |
            --- gender: male

Having the username as the document ID will ensure that you will have no duplicates because in a collection you cannot have two documents with the same ID.

If you reconsider your approach to using Security Rules, please check the following article before:

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM