🔥 gatsby firebase setup

Поделиться
HTML-код
  • Опубликовано: 10 дек 2024

Комментарии • 9

  • @impostorengineer
    @impostorengineer 3 года назад +1

    I think you should mention that in Test mode it allows anyone to read/write to your database, and you can change that to Locked mode or Auth required to secure it.

    • @bradgarropy
      @bradgarropy  3 года назад +1

      I'll do a dedicated video on Firestore rules in the future that will dive into this much deeper!

  • @a.m2490
    @a.m2490 3 года назад

    Yoo! I got an issue where i can't seem to upload anything to the firestore from the static site when it's built, but it works perfectly in develop mode. Researched a bit and got to understand that it's because we're using Webpack's dev server but not in the build, how do i work around this? Great content btw

    • @bradgarropy
      @bradgarropy  3 года назад

      Glad you're liking what I'm putting out!
      Do you have a repository I could take a look at? What's the error message you're getting? What tech are you using to build your website? Are you using environment variables for your Firestore keys, and if so, are they being injected properly? What are you Firestore rules?
      I know it's a ton of questions 😅 but instead of solving it in the RUclips comments head over to my Discord where I can help you out more effectively!
      bradgarropy.com/discord

  • @thehaptiK
    @thehaptiK 3 года назад

    yeah this runs in develop, but good luck getting it to run in production. building the project will fail in this example.

    • @bradgarropy
      @bradgarropy  3 года назад

      Can you provide a reproduction? What error message are you getting?

    • @thehaptiK
      @thehaptiK 3 года назад +1

      @@bradgarropy firebase requires node. if you're running in dev its run in the node env. Gatsby in production isn't node and therefore a request for node-fetch doesn't exist. so it fails unless you do extra work for gatsby ssr

    • @bradgarropy
      @bradgarropy  3 года назад

      You are correct that a production Gatsby build doesn't run node, it generates static files. However, Firestore is definitely supported from the client!
      This library from Google implements the client side Firebase SDK.
      github.com/firebase/firebase-js-sdk
      Even in their docs they describe it as both a client and server side implementation:
      "Use our flexible, scalable NoSQL cloud database to store and sync data for client- and server-side development."
      You are most likely attempting to run the web client SDK code during the build process. Be sure to only run the web client SDK from the browser, and not during the build process. You can do this by wrapping calls to Firestore in a useEffect, or checking if the window object exists before running the SDK.

    • @thehaptiK
      @thehaptiK 3 года назад +1

      @@bradgarropy thanks for the follow up advice and link! i might have to revisit an old project i gave up on now. you're the best!