简体   繁体   中英

How to get a user specific data from Firebase (Web) Database?

Authentication is done with Firebase Authentication and when an user is signed in to the website I redirect them to a new HTML page and access their User ID's from there. User's can add text to database but everyone who logs in to system can see the texts. I want only user's own text's to be seen. How can I show their own data from Firebase Realtime Database if I know their authentication user id?

You have to structure your database so that every time a user adds text, the user ID is associated with that specific piece of text. There are multiple ways to do this and it depends on the needs of your application.

Examples of a few different ways to structure your data with Realtime Database: https://firebase.google.com/docs/database/web/structure-data

Once your database is structured to associate data with user ID, you can set up an authentication state observer on your site to grab user data (like the ID of the currently logged in user). It sounds like you already have the user ID, but just in case, the docs show you how to do this: https://firebase.google.com/docs/auth/web/start#set_an_authentication_state_observer_and_get_user_data

Then, you can query your database with that user ID so that the user can only see their own text.

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