DEV Community

Discussion on: Beginner's Guide for Creating a Serverless REST API using NodeJS over Google Cloud Functions

Collapse
 
khmaies5 profile image
Khmaies Hassen

I have a dumb question :p
Why we have to build an api for firebase database and not directly use the firebase api to access our firestore database?

Collapse
 
levivm profile image
Levi Velázquez • Edited

This is a simple tutorial, I tried to keep our endpoints simpler as possible but most cases you need to have authentication, you need to do extra processes before inserting a record, you need to create an extra task, handle permissions, roles, etc. This is a backend service, it isn’t about just accessing database.

If you have any other question, feel free to ask :)

Collapse
 
dizid profile image
Marc de Ruyter

i have a url-shortener without users logging in. I cannot write to firestore from the Vue client because the firestore rules need a user logged in. I can also not use the firebase-admin because the code runs on the client. So, now i am trying a cloud function as an API relay.

Collapse
 
levivm profile image
Levi Velázquez

But you can authenticate using an anonymous login(it is available on firebase), so, you can login user using token generates from the client without having username or password.

Thread Thread
 
dizid profile image
Marc de Ruyter

HI Levi, Thanks for the tip, i will look into that!