I've been exploring ways to retrieve data from Firebase within GetServerSideProps in NextJs
Below is my db file setup:
import admin from "firebase-admin";
import serviceAccount from "./serviceAccountKey.json";
if (!admin.apps.length) {
try {
admin.initializeApp({
credential: admin.credential.cert(serviceAccount),
});
} catch (error) {
console.log("Firebase admin initialization error", error.stack);
}
}
export default admin.firestore();
Next, I use getServerSideProps to fetch the data:
export async function getServerSideProps(context) {
const id = context.params.profileId;
const doc = await db.collection("profile").doc(id).get();
const profile = doc.data();
return {
props: { profile },
};
}
An error message appears saying:
error - ./node_modules/@google-cloud/storage/build/src/bucket.js:21:0
Module not found: Can't resolve 'fs'
I'm wondering if there's an alternative method to interact with Firebase that doesn't rely on a Node Library requiring access to the filesystem. Any suggestions or workarounds would be greatly appreciated.
Thank you!