Leave a comment →Powered by Fast Feedback (Alpha)

Rusith Gayashan

Sep 24, 2020, 10:52:32 PM

Isn't it better to directly use firebase in the client rather than creating an API Route? Is there a specific reason to do it this way?


Lee Robinson

Sep 28, 2020, 2:44:11 AM

@Rusith The biggest advantage of using Firebase Admin is that you can utilize getStaticProps/getStaticPaths/getServerSideProps in Next.js, which are all ran on the server. When you use the Client SDK, you're limited to client-side rendering only.

One of the biggest advantages of Next.js is its hybrid approach. You can do client-side rendering, server-side rendering, and a mix of both in the same application. The example above is serving a static loading state from the server, followed by fetching data from an API route. This helps reduce the TTFB and improve performance.

With that being said, client-side rendering still has it's place. Especially with the reactfire hooks the Firebase team is working on.


Constantine

Nov 7, 2020, 8:47:53 PM

Awesome!

Right now, I am in a similar situation. Investigating next.js + firebase stack. Your post really helps.

Thanks for you work!