fire-base functions 6.0.1 incompatible? #1579
Replies: 2 comments
-
How were you able to (hopefully) work this out? |
Beta Was this translation helpful? Give feedback.
-
I asked Google Gemini and ChatGPT about functions and Vuefire in a SSR Nuxt 3 app and here is the response: Below is a comprehensive look at whether to use VueFire in a Nuxt 3 SSR app with Pinia and Firebase, why or why not, and what to do instead if VueFire isn’t your best fit. 1. What Does VueFire Do?
2. Why VueFire Is Not Commonly Used for Nuxt SSR + Pinia + Firebase Functions
3. When Might You Consider VueFire Anyway?
4. Recommended Approach (Nuxt 3 + Pinia + Firebase)
Example: Pinia Action for Firestore// stores/products.ts
import { defineStore } from 'pinia'
import { collection, getDocs } from 'firebase/firestore'
export const useProductsStore = defineStore('products', {
state: () => ({
products: [] as any[],
loading: false,
error: null as string | null,
}),
actions: {
async fetchProducts() {
this.loading = true
this.error = null
try {
const { $firestore } = useNuxtApp()
const productsRef = collection($firestore, 'products')
const snapshot = await getDocs(productsRef)
this.products = snapshot.docs.map((doc) => ({ id: doc.id, ...doc.data() }))
} catch (err: any) {
this.error = err.message
} finally {
this.loading = false
}
},
},
}) Example: SSR-Fetching in a Nuxt Page<!-- pages/index.vue -->
<template>
<div>
<p v-if="productsStore.loading">Loading...</p>
<p v-else-if="productsStore.error">Error: {{ productsStore.error }}</p>
<ul>
<li v-for="product in productsStore.products" :key="product.id">
{{ product.name }} - ${{ product.price }}
</li>
</ul>
</div>
</template>
<script setup>
import { useProductsStore } from '@/stores/products'
// We'll fetch data on the server (SSR) and pass it to our store
const productsStore = useProductsStore()
// Use useAsyncData to run fetchProducts() on server-side
const { data, refresh } = await useAsyncData('products', async () => {
await productsStore.fetchProducts()
return productsStore.products
})
// Now 'data.value' will have the products if you want direct usage
// but since we're storing them in Pinia, it's optional to read from data.value.
</script> This approach ensures your data is available for SSR, quickly hydrated on the client side, and centrally managed in Pinia. 5. Final Verdict
Overall, continue to use your Pinia stores and call Firebase or Cloud Functions directly. That’s the clean, conventional approach for Nuxt 3 SSR. |
Beta Was this translation helpful? Give feedback.
-
ran
pnpm add firebase-functions
and it added 6.0.1, now I get:Anything special I should do here? Downgrade to ^5.0.0?? Thanks.
Beta Was this translation helpful? Give feedback.
All reactions