Next.js Discord

Discord Forum

Fetching data on the server using next 14

Unanswered
Drentse Patrijshond posted this in #help-forum
Open in Discord
Drentse PatrijshondOP
i created

import "server-only";

import { getFirestore } from "firebase-admin/firestore";
import { cookies } from "next/headers";

export const getInvoices = async () => {
const cookieStore = cookies();
const userId = cookieStore.get("userId");

const firestore = getFirestore();
const snapshot = await firestore
.collection(businesses/${userId}/invoices)
.get();
const invoices = snapshot.docs.map((doc) => ({ id: doc.id, ...doc.data() }));
console.log("snapshot", invoices);

return snapshot;
};



this firebase file and am calling it here

import Invoices from "@/components/invoices";
import { initAdmin } from "../../../../firebaseAdmin";
import { getInvoices } from "@/serverFetchFirebase.ts/firebase";

export default async function InvoicesPage() {
await initAdmin();
const invoices = await getInvoices();

console.log("invoices", invoices);

return <Invoices invoices={invoices} />;
}



and im getting

Error: 2 UNKNOWN: Getting metadata from plugin failed with error: error:1E08010C:DECODER routines::unsupported
for call at
Caused by: Error
at getInvoices (./src/serverFetchFirebase.ts/firebase.ts:17:82)
at InvoicesPage (./src/app/dashboard/invoices/page.tsx:11:105)

-- anyone can help and guide me if im doing this correctly

1 Reply

Drentse PatrijshondOP
found the issue wityh env variables that are not working