<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Rzcodes  on Medium]]></title>
        <description><![CDATA[Stories by Rzcodes  on Medium]]></description>
        <link>https://medium.com/@rzcodes?source=rss-97da66e615ec------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*95bzB4QyADprNsYj</url>
            <title>Stories by Rzcodes  on Medium</title>
            <link>https://medium.com/@rzcodes?source=rss-97da66e615ec------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 07:24:36 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@rzcodes/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[How to deploy Next.js app using Firebase Hosting, Gitlab and Nx]]></title>
            <link>https://medium.com/@rzcodes/how-to-deploy-next-js-app-using-firebase-hosting-gitlab-and-nx-7ada578012ec?source=rss-97da66e615ec------2</link>
            <guid isPermaLink="false">https://medium.com/p/7ada578012ec</guid>
            <category><![CDATA[firebase]]></category>
            <category><![CDATA[nextjs]]></category>
            <category><![CDATA[gitlab-ci]]></category>
            <category><![CDATA[firebasehosting]]></category>
            <category><![CDATA[devops]]></category>
            <dc:creator><![CDATA[Rzcodes ]]></dc:creator>
            <pubDate>Mon, 24 Jun 2024 19:50:24 GMT</pubDate>
            <atom:updated>2024-06-24T20:06:07.628Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/851/1*rwn1qvbrL68MavDDqBW5Mw.png" /></figure><p>Deploying Next.js app on Firebase Hosting requires few step to get your app up and running. <a href="https://nx.dev/">Nx</a> provides you a comprehensive build system to structure your multiple apps into a single repository. In the tutorial we are going to see how to deploy a <a href="https://next.org/">Next.js</a> app as a <a href="https://nextjs.org/docs/pages/building-your-application/rendering/static-site-generation">Static Site Generation(SSG)</a> using Firebase Hosting. Let’s start by setting up Nx workspace and adding our Next.js app.</p><h3>Setting up Nx workspace and adding Next.js app</h3><p>Here are the steps to initialize a new nx workspace and add our Next.js app</p><ol><li><strong>Initialize a new Nx workspace</strong>:</li></ol><ul><li>First, install the Nx CLI globally by running npm install -g nx.</li><li>Then, create a new Nx workspace by running npx create-nx-workspace@latest.</li><li>Setup the repo using your preferences although the default once would do you just enough to get started.</li></ul><p><strong>2. Create a new Next.js application</strong>:</p><ul><li>In your Nx workspace, create a new Next.js application by running nx g @nrwl/next:application next-app.</li></ul><p>Once your done generating the app goto next.config.js file add the output:export option to the nextConfig object</p><pre>//@ts-check<br><br>// eslint-disable-next-line @typescript-eslint/no-var-requires<br>const { composePlugins, withNx } = require(&#39;@nx/next&#39;);<br>const path = require(&#39;path&#39;);<br><br>/**<br> * @type {import(&#39;@nx/next/plugins/with-nx&#39;).WithNxOptions}<br> **/<br>const nextConfig = {<br>  output: &#39;export&#39;, // add this line<br>  nx: {<br>    // Set this to true if you would like to use SVGR<br>    // See: https://github.com/gregberge/svgr<br>    svgr: false,<br>  },<br>  webpack: (config, { buildId, dev, isServer, defaultLoaders, webpack }) =&gt; {<br>    config.resolve.alias[&#39;@&#39;] = path.join(__dirname, &#39;src&#39;);<br>    return config;<br>  },<br>};<br><br>const plugins = [<br>  // Add more Next.js plugins to this list if needed.<br>  withNx,<br>];<br><br>module.exports = composePlugins(...plugins)(nextConfig);</pre><p>The outout directory is the default distDir used by Next.js to export your app to a statically generated file.</p><h3>Setting up Firebase project</h3><p><a href="https://firebase.google.com/">Firebase</a> is an excellent choice for prototyping web applications due to its comprehensive suite of development tools and services. It offers a real-time database, user authentication, cloud storage, hosting, and much more out of the box. This allows developers to rapidly build and prototype applications without having to manage infrastructure or write server-side code.</p><p>Firebase’s support for CI/CD through tools like GitLab CI/CD makes it possible to automate the deployment process, thus further speeding up the development cycle and ensuring that your application is always up-to-date with the latest features and improvements.</p><ol><li><strong>Create a new Firebase project</strong>:</li></ol><ul><li>Go to the <a href="https://console.firebase.google.com/">Firebase Console</a>.</li><li>Click on “Add project”.</li><li>Follow the prompts to add a new project.</li></ul><p><strong>2. Install Firebase tools</strong>:</p><ul><li>Install the Firebase CLI globally by running npm install -g firebase-tools.</li><li>Login to Firebase CLI by running firebase login:ci This will help you to choose your firebase projects from the terminal.</li></ul><p><strong>3. Initialize Firebase in your Next.js application</strong>:</p><ul><li>Navigate to the next-app directory where you generated you Next.</li><li>Run firebase init.</li><li>Choose “Hosting” when prompted for which Firebase features you want to set up.</li><li>Choose your Firebase project, continue with the options you want ot sent and finally choose “out” as your public directory.</li></ul><blockquote>Make sure you have your build directory defined in next.config.mjs matches the ones defined on firebase.json. If you have not defined any distDir in next.config.mjs, “out” will be your default directory</blockquote><p>Your firebase.json file should like something similar to this</p><pre>{<br>  &quot;comment&quot;: &quot;add this after your exiting configs like firestore or functions&quot;,<br>  &quot;hosting&quot;: {<br>    &quot;public&quot;: &quot;out&quot;,<br>    &quot;ignore&quot;: [&quot;firebase.json&quot;, &quot;**/.*&quot;, &quot;**/node_modules/**&quot;],<br>    &quot;frameworksBackend&quot;: {<br>      &quot;region&quot;: &quot;us-centeral1&quot;<br>    }<br>  },<br><br>}</pre><h3>Setting up Gitlab CI/CD</h3><p>Now, whenever you push changes to the master branch of your GitLab project, GitLab CI/CD will automatically build and deploy your Next.js application to Firebase.</p><p>To add CI/CD to your next app. We need to create a .gitlab-ci.yml file at the root of our nx application. Once you create the file, define the stages for linting, building and deploying. In the example below we have three environments, dev, uat and prod.</p><p>You can copy and paste this as a sample and adjust stage as your app needs.</p><pre>image: node:latest<br><br>stages:<br>  - lint<br>  - build<br>  - deploy<br><br>lint:<br>  stage: lint<br>  script:<br>    - echo &quot;Linting the next-app&quot;<br>    - npm install<br>    - npm run lint<br><br>build:<br>  stage: build<br>  script:<br>    - echo &quot;Building next-app&quot;<br>    - npx nx build next-app --verbose<br>  <br>before_script:<br> - echo $GOOGLE_APPLICATION_CREDENTIALS &gt; /tmp/key.json<br> - export GOOGLE_APPLICATION_CREDENTIALS=/tmp/key.json<br>  <br>  <br>deploy_dev:<br>  stage: deploy<br>  environment:<br>   - dev #fetchs env vars for dev only<br>  only:<br>    - dev<br>  script:<br>    - npx firebase deploy --debug # you can remove `--debug` <br>  <br>deploy_release:<br>  stage: deploy<br>  environment: <br>   - release #fetchs env vars for release <br>  only:<br>    - release <br>  script:<br>    - npx firebase deploy <br>    <br>deploy_prod:<br>  stage: deploy<br>  environment: <br>   - main #fetchs env vars for prod <br>  only:<br>    - release <br>  script:<br>    - npx firebase deploy </pre><blockquote>Make sure that GOOLGE_APPLIATION_CREDENTIALS is readable by the CI job when you pass in the key file to tmp/key.json</blockquote><p>Since Firebase has deprecated using --token to allow authentication of external services like GitLab CI, we need to apply the new approach for authentication. Google recommends to use a service account key with GOOGLE_APPLICATION_CREDENTIALS. To get this key you need to generate a service account key from the Google Cloud Console and then set it as an environment variable in your GitLab CI/CD pipeline. Here&#39;s how you can do it:</p><ol><li><strong>To generate a service account key</strong>:</li></ol><ul><li>Go to the <a href="https://console.cloud.google.com/">Google Cloud Console</a>.</li><li>Select your project.</li><li>Go to IAM &amp; Admin &gt; Service Accounts.</li><li>Click on “Create Service Account”.</li><li>Fill in the details and click “Create”.</li><li>Grant this service account an appropriate role. For Firebase, the “<strong>Firebase Admin</strong>” role should be sufficient.</li><li>Click “Done” to create the service account.</li><li>Click on the row of the service account that you just created.</li><li>Click on “<strong>Add Key</strong>” and then “Create new key”.</li><li>Select “<strong>JSON</strong>” and click “<strong>Create</strong>”. This will download a JSON file with your service account key.</li></ul><p><strong>2. Set the service account key as an environment variable</strong>:</p><ul><li>Open the downloaded JSON file and copy its contents.</li><li>Go to your GitLab project.</li><li>Go to Settings &gt; CI/CD &gt; Variables.</li><li>Click on “<strong>Add Variable</strong>”.</li><li>Set the key to GOOGLE_APPLICATION_CREDENTIALS and the value to the contents of the JSON file (The key file you downloaded in the above step).</li><li>Click “Add Variable” to save it.</li></ul><p>Once you save the GOOGLE_APPLICATION_CREDENTIALS you can now push changes to one of your defined branches and Gitlab CI will automatically tirgger the job to build and deploy your application.</p><p>I hope this guide will help you to deploy your apps within the Nx using Firebase Hosting and Gitlab CI. Feel free to give it your thoughts or suggestion. If you find it useful save and share it for others. <a href="https://rz-codes.com/">Connect with me</a> to get more related content on web development.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7ada578012ec" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to access nested sub-collections in Firebase]]></title>
            <link>https://medium.com/@rzcodes/how-to-access-nested-sub-collections-in-firebase-c678664c621c?source=rss-97da66e615ec------2</link>
            <guid isPermaLink="false">https://medium.com/p/c678664c621c</guid>
            <category><![CDATA[firestore]]></category>
            <category><![CDATA[nosql]]></category>
            <category><![CDATA[firebase]]></category>
            <dc:creator><![CDATA[Rzcodes ]]></dc:creator>
            <pubDate>Thu, 11 Apr 2024 08:52:11 GMT</pubDate>
            <atom:updated>2024-04-11T08:52:11.645Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*c-QVf0GI3qjUVns6pSHpOw.png" /></figure><p>In the realm of modern application development, Firebase has emerged as a powerful tool, offering a comprehensive suite of services to facilitate backend development without the hassle of managing infrastructure. One of the key features of Firebase is Firestore, a flexible, scalable database that allows for efficient storage and retrieval of data. Firestore organizes data into collections and documents, providing a hierarchical structure that can be further enhanced through nested subcollections.</p><p>However, navigating nested subcollections in Firestore can sometimes be challenging for developers, especially those who are new to the platform. In this blog post, we’ll delve into the intricacies of accessing nested subcollections in Firebase Firestore, providing insights and practical tips to simplify the process.</p><h3>Understanding Firestore Data Structure</h3><p>Before diving into nested subcollections, it’s essential to grasp the fundamental structure of Firestore data. Firestore organizes data into collections, which are containers for documents. Each document contains fields and can also contain nested collections, creating a hierarchical structure that mirrors real-world data relationships.</p><p>For example, consider a simple Firestore structure for a blogging platform:</p><pre>users (collection)<br>   └── userId (document)<br>         └── posts (subcollection)<br>               └── postId (document)<br>                     └── comments (subcollection)<br>                           └── commentId (document)</pre><h3>Accessing Nested Subcollections</h3><p>Accessing data within nested subcollections involves traversing through multiple levels of collections and documents. Let’s break down the process step by step:</p><ol><li><strong>Accessing a Collection</strong>: Begin by referencing the top-level collection using its name. For example, to access the users collection:</li></ol><pre>const usersRef = firebase.firestore().collection(&#39;users&#39;);</pre><p><strong>2. Accessing a Document</strong>: Once you have a reference to the collection, you can retrieve a specific document within that collection using its document ID. For example, to access the document with userId:</p><pre>const userDocRef = usersRef.doc(userId);</pre><p><strong>3. Accessing a Subcollection</strong>: If the document contains a subcollection, you can access it using its name. For example, to access the posts subcollection within a user document:</p><pre>const postsRef = userDocRef.collection(&#39;posts&#39;);</pre><p><strong>4. Querying Documents within Subcollection</strong>: Finally, you can query documents within the subcollection using Firestore queries. For example, to retrieve all posts for a particular user:</p><pre>postsRef.get().then((querySnapshot) =&gt; {<br>    querySnapshot.forEach((doc) =&gt; {<br>        console.log(doc.id, &#39; =&gt; &#39;, doc.data());<br>    });<br>});</pre><h3>Best Practices and Considerations</h3><p>When working with nested subcollections in Firestore, keep the following best practices in mind:</p><ul><li><strong>Keep Data Structure Simple</strong>: While nested subcollections offer flexibility, avoid excessive nesting to maintain simplicity and optimize query performance.</li><li><strong>Use Composite Indexes</strong>: If you frequently query documents within nested subcollections, consider creating composite indexes to improve query performance.</li><li><strong>Consider Denormalization</strong>: In some cases, denormalizing data by duplicating it across collections may simplify queries and improve performance.</li><li><strong>Security Rules</strong>: Ensure that your security rules appropriately secure access to nested subcollections based on your application’s requirements.</li></ul><h3>Conclusion</h3><p>Firebase Firestore’s support for nested subcollections offers developers a powerful tool for organizing and querying data in a scalable and efficient manner. By understanding the structure of Firestore data and following best practices, developers can effectively access and manipulate nested subcollections to build robust and performant applications.</p><p>Whether you’re building a social network, e-commerce platform, or any other type of application, mastering the art of accessing nested subcollections in Firestore is a valuable skill that will undoubtedly enhance your development journey. With the insights and tips provided in this guide, you’re well-equipped to navigate the depths of Firebase Firestore and unleash its full potential in your projects. Happy coding!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c678664c621c" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>