Accessing FireStore from client-side app
Working with Google's services such as Firebase, Google Analytics, or Google Cloud Platform can often be a source of frustration for me. The primary issue is their documentation, which tends to be unclear or difficult to comprehend.
Working with Google's services such as Firebase, Google Analytics, or Google Cloud Platform can often be a source of frustration for me. The primary issue is their documentation, which tends to be unclear or difficult to comprehend. Additionally, the frequent, sometimes annual, changes to their APIs can be a major headache, as it complicates the maintenance of any projects built on these platforms. But... sometimes you gotta do what you gotta do.
I recently needed to integrate user profiles with the Firebase authentication module directly in a client-sided application (Next.js).
The idea of connecting to a database from the client side might seem risky, but Firebase's security rules help mitigate this. They allow safe enough interactions where an attacker is only able to modify their own data, which is a useful safeguard.
To set up a client app with Firebase, you start by creating instances for each service as follows:
For executing operations using the database, here's an example code snippet for inspiration:
Official FireStore API reference can be found here: https://firebase.google.com/docs/reference/js/firestore
Published on January 15, 2024 • 2 min read