Tutorials on Firebase

Learn about Firebase from fellow newline community members!

  • React
  • Angular
  • Vue
  • Svelte
  • NextJS
  • Redux
  • Apollo
  • Storybook
  • D3
  • Testing Library
  • JavaScript
  • TypeScript
  • Node.js
  • Deno
  • Rust
  • Python
  • GraphQL
  • React
  • Angular
  • Vue
  • Svelte
  • NextJS
  • Redux
  • Apollo
  • Storybook
  • D3
  • Testing Library
  • JavaScript
  • TypeScript
  • Node.js
  • Deno
  • Rust
  • Python
  • GraphQL

A Comparative Analysis between Firebase, Amplify, and Supabase for Your Next.js Application

In this blog, I will explore a critical decision that Indie Hackers and startups often grapple with, which is selecting the ideal real-time database platform for building a Real-Time Collaborative Application with Next.js. My focus in this blog will be on Firebase , AWS Amplify , and Supabase , dissecting their features, limitations, and costs, and ultimately pinpointing the most suitable platform for Indie Hackers. When it comes to platforms for real-time database applications, three platforms stand out: Firebase , AWS Amplify , and Supabase . Each has its strengths, but not all are perfectly tailored to the specific requirements of Indie Hackers, particularly those primarily concerned with developing a Minimum Viable Product (MVP) and swift feature development and testing. Firebase is a powerful platform, but it may prove expensive for Indie Hackers and startups. Firebase faces scalability challenges, particularly as user base and complexity increase. Its pricing model can become expensive with high database operations and extensive bandwidth usage. Additionally, Firebase's limited query capabilities can lead to performance issues in larger datasets, requiring additional services or workarounds. Also, its single-region hosting for databases can cause higher latencies for global applications, negatively affecting user experience. Managing these aspects often involves careful planning and integration with other services to maintain performance and cost efficiency at scale. Amplify provides smooth integration with AWS services but it requires a thorough grasp of the AWS ecosystem and its intricacies. Moreover, AWS's billing structures can be complex and hard to navigate, adding an additional layer of complexity for Indie Hackers and startups. In contrast to Firebase and Amplify , Supabase , equipped with Firebase-like features, is open-source and thus free of cost. With features such as a Postgres database, Authentication, instant APIs, Edge Functions, Realtime subscriptions, Storage, and Vector embeddings, you can construct your MVP using Supabase within a weekend. Supabase also boasts a user-friendly dashboard and UI tools for managing and visualizing data, enhancing its accessibility. Supabase stands out for its superior real-time communication between the client and server, the cornerstone of all real-time full-stack applications. Putting Firebase and Amplify aside as database platforms, we still need to comprehend why Supabase outperforms other alternatives like webSockets or algorithms such as Conflict-free Replicated Data Type (CRDT) or Operational Transformation (OT) for immediate database read and write operations. WebSockets necessitate handling all the server-side setup and related costs. Moreover, you're likely to face complications regarding scalability, firewall and proxy issues, bandwidth and server resources overhead, and connection management, among others. Supabase encompasses all the critical elements for a successful Real-Time Collaboration Application, making it the perfect platform for rapidly developing and testing an MVP. 1 to 1 Chat Supabase can efficiently handle 1 to 1 chats through its real-time subscriptions, allowing direct and immediate updates for messages between two users. Its built-in authentication and security features also simplify managing user identities and permissions. Room Chat For room chats, where multiple users communicate in a shared space, Supabase's real-time updates ensure that messages are consistently and instantly pushed to all participants in the room. This scenario benefits from the robust backend structure Supabase provides, although managing larger groups might require careful handling of data throughput and connection limits. Real-time Dashboards Applications that require real-time monitoring and reporting can leverage Supabase’s instant APIs and real-time capabilities to display updated data without delay. IoT Applications In scenarios where IoT devices send continuous data streams to the backend, Supabase can handle real-time data ingestion and updates efficiently, making it suitable for real-time tracking and monitoring applications. Why opt for Next.js for your tech stack? The justification lies in the Indie Hacker's objective: to create and test an MVP within a single week that can be scaled from 10 to a million users seamlessly. Next.js accelerates the development process with its support for server-side rendering (SSR) and static site generation (SSG), enabling rapid setup of a performant, SEO-friendly front-end. This flexibility allows for fast loading times, crucial for retaining users during the MVP phase. The framework also simplifies page creation and management through its file-based routing system, where adding a JavaScript file in the pages directory automatically configures routing. API routes can be seamlessly created within the same project structure, streamlining the handling of backend functionalities directly alongside the front end, which is essential for quickly testing hypotheses. Next.js integrates well with Supabase, which handles backend functionalities like database operations, authentication, and real-time updates efficiently. This combination allows for dynamic and interactive applications. Tailwind CSS's utility-first approach facilitates rapid, customizable styling, enabling quick design iterations without heavy CSS overheads, complementing Next.js's fast development cycle. The framework is built with scalability in mind, effectively handling increases in traffic from a few users to millions. Features like automatic code splitting, lazy loading, and image optimization ensure that only necessary resources are loaded, enhancing performance. For global scalability, Next.js supports incremental static regeneration, allowing pages to be pre-rendered and updated incrementally, thus reducing server load and improving user experience across different regions. Finally, Next.js benefits from robust community support and a rich ecosystem of plugins and integrations, thanks to its affiliation with the Vercel platform. This vast community resource pool and third-party tool availability extend the functionality of applications, making Next.js a reliable choice for developers aiming to build and scale an MVP rapidly. This framework, in combination with Supabase, Tailwind CSS, and TypeScript, offers a comprehensive solution for developing high-quality applications efficiently. To wrap up, while Firebase and Amplify do have their merits, but their cost and complexity make them less suitable for Indie Hackers and startups. Conversely, Supabase , with its open-source status, comprehensive features, and user-friendly interface, emerges as the top choice. Paired with Next.js , it offers a robust platform for creating and testing MVPs for Real-Time Collaborative Apps. For more insights visit Real-Time Collaborative Web Applications with Next.js and Supabase , TypeScript , and Tailwind CSS . When used in conjunction, these tools form a well-rounded tech stack that can expedite Indie Hackers' journey toward their goals.

Building an API using Firebase Functions for cheap

When I am working on personal projects, I often find the need to setup an API that serves up data to my app or webpages. I get frustrated when I end up spending too much time on hosting and environment issues. These days what I end up doing is hosting the API using Cloud Functions for Firebase . It hits all my requirements: The official name is Cloud Functions for Firebase. In this article, I am going to call it Firebase Functions. This is mostly to distinguish it from Google's other serverless functions-as-a-service: Cloud Functions. You can read more about the differences here . From that page: While I'm not going to write a mobile app in this article, I like to use Firebase Functions because: If all this isn't confusing enough, Google is rolling out a new version of Cloud Functions called 2nd generation which is in "Public Preview". So in order to move forward, let's identify our working assumptions: After all this is complete, you should have a single file called firebase.json and a directory called functions . The functions directory is where we'll write our API code. We'll take the emulator out for a spin. Congrats, you have Firebase Functions working on your local system! To exit the emulator, just type 'Ctrl-C' at your terminal window. This is all very exciting. Let's push our new "hello world" function into the cloud. From the command line type: The output should look similar, but not exactly to: And if we navigate to the Function URL we should get the 'Hello from Firebase!' message. Exciting! Do you see how easy it is to create Firebase Functions? We've done all the hard part of setting up our local environment and the Firebase project. Let's jump into creating an API using Express Install express: Next, edit the index.js file to look like: Then if you run You can load up your api locally. Note the URL link on the emulator is a little different -- it should have 'api' added at the end like: You should see our 'Hello World' message. Now for more fun, add '/testJSON' to the end of your link. You should see the browser return back JSON data that our API has sent: Now finally, let's deploy to the cloud: Note that when you try to deploy, Firebase is smart enough to detect that major changes to the URL structure have occurred. You'll need to verify that you did indeed make these changes and everything is ok. Since this is a trivial function, you can type Yes . Firebase will delete the old function we deployed earlier and create a new one. Once that completes, try to load the link and validate your API is now working! This article has walked you through the basics of using Firebase Functions to host your own API. The process of writing and creating a full featured API is beyond the scope of this article. There are many resources out there to help with this task, but I hope you'll think about Firebase Functions next time you are starting a project.

Thumbnail Image of Tutorial Building an API using Firebase Functions for cheap

I got a job offer, thanks in a big part to your teaching. They sent a test as part of the interview process, and this was a huge help to implement my own Node server.

This has been a really good investment!

Advance your career with newline Pro.

Only $30 per month for unlimited access to over 60+ books, guides and courses!

Learn More

Firebase Authentication with React

In this article, we will learn how to implement Firebase authentication in a React app.Firebase is an increasingly popular platform that enables rapid development of web and mobile apps. It offers a number of services such as a real-time database, cloud functions and authentication against various providers. In the following sections, we will build a React app that has three screens: Let's create a new project on the Firebase Console . We will call our project react-firebase-auth Once the project is created, we will navigate to the 'Authentication' tab to set up sign-in methods. For now, let us enable sign-ins with a username and password. The only other thing left to do before we start building our React app, is to add it to the Firebase project. Once we add a web app to our project, Firebase gives us the app configuration, that looks somewhat like this: We will add these configuration values into the .env file in our app. Let's use create-react-app to generate a stock React app. We'll call our app react-firebase-auth . Once this is done, we need to add a few dependencies using yarn add : In the app's .env file, we need to add the values supplied by Firebase in Step 1 like so: More information about how environment variables work can be found in the Create React App documentation . In the src folder, let us create a base.js file where we will set up the Firebase SDK. In app.js , we will wrap our app with the Router component from react-router-dom which will allow us to use routes, links and redirects. In order to store the authentication status and make it globally available within our app, we will use React's context API to create an AuthContext in src/Auth.js . We will hold the currentUser in the state using the useState hook, and add an effect that will set this variable whenever the Firebase auth state changes. We also store a pending boolean variable that will show a 'Loading' message when true. In essence, the currentUser will be null when logged out and be a defined object when the user is logged in. We can use this to build a PrivateRoute component which allows the user to access a route only when logged in. The PrivateRoute component takes a component prop which is rendered when the user is logged in. Otherwise, it redirects to the /login route. We can now use this in our app.js file after wrapping our app with the AuthProvider : Let us now implement the screens that make up our app. We can start with the simplest one, which is the home screen. All it will have is the title 'Home' and a 'Sign out' button that logs the user out of the app. This is done by calling the signOut method from Firebase's auth module. Let's now move on to the signup page, which is slightly more complex. It will have the header 'Sign up', with a form that includes text inputs for email and password, and a submit button. We wrap the component with the withRouter HOC to provide access to the history object. When the form is submitted, we will use the createUserWithEmailAndPassword method from Firebase's auth module to sign the user up. We display an alert in case something goes wrong during this process. If the user creation succeeds, we redirect the user to the home ( / ) page using the history.push API. The login page is very similar to the sign up page, with an identical-looking form. The only difference is that we will log the user in rather than create a new user when the form is submitted. The component also uses the currentUser value from our AuthContext , and will redirect to the / route when the user is logged in. And there we have it - we have just implemented a React app with sign up, login and home screens that uses Firebase authentication to register and authenticate users with their email and password. We have now learned how to implement Firebase authentication with a React app. The code used in this article is available at https://github.com/satansdeer/react-firebase-auth and a video version of this article can be found on YouTube .

Thumbnail Image of Tutorial Firebase Authentication with React