How to write data in firebase realtime database - database

I am working with firebase in html, and it shows my users in the firebase authentication. Only problem is that id don't know how to write data of some other sort. pls help bye

Related

Chat with React and Realtime database firebase. Do I need backend? How can I structure my data?

I'm working on a project using React 18 with Firebase Authentication and Realtime Database.
The project is a real-time chat between two users, I wan't this project to be very secure and protect messages/conversations. I have the following "cases" or "rules" to specify this chat functions:
User with profile Volunteer can chat with maximum 10 users with the simple-user profile.
Volunteer can see previous messages or the "history" with a registered simple-user but simple-user can't see previous messages. I need to protect chats for simple-user.
All the active "chats" between one volunteer and maximum 10 simple-users have to be seen just for the Volunteer profile. The simple-user just send and receive messages with a random Volunteer.
I search on the Internet which database fit better with my project model and Realtime Database looks like the better option. But now I would like to have your opinions about how can I handle the database to get the data and connection that I need according to the previous rules I wrote.
I know Firebase is a No-SQL database, but I create this diagram to know if the data structure for this chat could work.
If I store different information like the image above, could I get the information I need from each chat?
Turn is the working shift time that "volunteer" is working on the chat platform.
Session is the information of the turn of that volunteer and simple-users that they talk.
Chat is the "conversation" or the instance to generate messages between two different users.
My questions are:
Do I need a backend project such as nodejs? This backend would be for store the endpoints to firestore and apply some logic rules for queries this way I can have a React project without logic
If I structure my database like the image above, can I be able to get the information to achieve the "rules" that I need?
Do you have any suggestion to build a chat like this? In the future this project could be huge with a lot of data store and multiple users chatting with each other. Right now I have just the UI code and firebase connection. No other code yet.
Thanks for your contributions!

How do I identify which user logged into my app via firebase auth?

This is an architectural design question.
I'm working on a React application that has a Spring boot (CRUD) backend, and I've recently added a Firebase Auth set-up for logging in and out. So far, users can log in/log out and then update a TODO list and save to a H2 database.
The issue is that I don't know how to relate user logins via firebase, to the DB updates. For example, a user logs in and updates the TODO list, when they hit save, I want to store their updated data in a DB table. I don't know how to relate the saved information to that user so that they get the correct TODO list information the next time they log in. I obviously want to avoid the situation where a user sees everyone else's data.
To do this should I store their UID from firebase? I want to avoid storing email addresses.
The application is a CRUD model. If there's a good way to implement what I currently have with firebase auth, then great. But if not, I'm willing to rip out the CRUD backend and use a firebase No/SQL DB instead.
Any suggestions would be greatly appreciated.
The idiomatic way to associate database information with a Firebase Authentication is indeed to store the UID of that user with the information.
If the write happens from you own backend code, ensure that the user can only associate data with their own UID by following this process:
Get the ID token from the user in the client-side application code.
Pass that ID token to your server-side code over a secure connection.
Decode and verify the ID token on the server.
Use the UID from the decoded token in the data, and ensure the user is authorized to perform the operation.
For more on this, see the Firebase documentation on verifying ID tokens.

React Firestore how to create a unique url when posting document to firestore

Not sure where to start on this one, so here goes.
After creating a document in Firestore by POSTing data the user inputs in my React application state, how can I create a unique URL that a user can visit to GET/view that data?
For example:
https://myreactwebsite.com/new-document/
I need to ensure that a unique URL exists in my website index, so that not only can a user visit, but it can be indexed by Google for SEO.
My React application is hosted on Firebase as well as using Firestore for the database.
Firestore is a NoSQL Document database (Much like MongoDB if you're familiar with it). They both implement some form of document ID in each document. That could be leveraged in creating a unique route in your use case.
I would create a route such as /profile/:id in your react app, that when you visit it you make a call to your backend requesting that profile and then use the response from that request to fill in the data.
I would try to describe it here but in all honesty, this page does a much better job than I could in one short SO post

Firebase Database cannot access today

Helo,
I Have problem accessing Firebase Database today. anyone have same problem with me?
I try go to Authentication , or storage no problem . Only database it won't show on dashbord
Everthing work for me (Cloud firestore and Firebase Database)
May be you have no data there so it is showing the create new database page. Type https://console.firebase.google.com/u/2/project/yourProjectId/database/yourProjectId/data on the search bar, and you will be there. Don't forget to replace yourProjectId with your project ID.

Send an email when records are added to Firebase database

I would like to send an email to the signed user with the data that was added by the user to the Firebase database. I am using AngularJS UI. Is there are Firebase module which will trigger email with the data being added to the signed user.
Thanks, Rajesh
You should look into Cloud Functions for Firebase. This will let you write database triggers that run on Google servers that can act whenever data in your database changes. There is plenty of sample code the illustrates some of the many things you can do, including one specific example that shows how to send email in response to a change in the database.

Resources