diff --git a/nextjs-end/src/app/actions.js b/nextjs-end/src/app/actions.js index 8eb5912b7..ec7b21af1 100644 --- a/nextjs-end/src/app/actions.js +++ b/nextjs-end/src/app/actions.js @@ -1,12 +1,17 @@ "use server"; import { addReviewToRestaurant } from "@/src/lib/firebase/firestore.js"; +import { getAuthenticatedAppForUser } from "@/src/lib/firebase/firebase"; +import { getFirestore } from "firebase/firestore"; // This is a next.js server action, an alpha feature, so // use with caution // https://nextjs.org/docs/app/building-your-application/data-fetching/server-actions export async function handleReviewFormSubmission(data) { - await addReviewToRestaurant(data.get("restaurantId"), { + const { app } = await getAuthenticatedAppForUser(); + const db = getFirestore(app); + + await addReviewToRestaurant(db, data.get("restaurantId"), { text: data.get("text"), rating: data.get("rating"), diff --git a/nextjs-end/src/lib/firebase/firebase.js b/nextjs-end/src/lib/firebase/firebase.js index 116e7ffba..e18cafc4e 100644 --- a/nextjs-end/src/lib/firebase/firebase.js +++ b/nextjs-end/src/lib/firebase/firebase.js @@ -1,26 +1,3 @@ -// import firebaseConfig from "@/src/lib/firebase/config.js"; -// import { initializeApp } from "firebase/app"; - -// import { getFirestore, connectFirestoreEmulator } from "firebase/firestore"; - -// import { getAuth, connectAuthEmulator } from "firebase/auth"; - -// import { getStorage, connectStorageEmulator } from "firebase/storage"; - -// import { getApps } from "firebase/app"; - -// let app = getApps().length === 0 ? initializeApp(firebaseConfig) : getApps()[0]; - -// export const db = getFirestore(app); -// export const storage = getStorage(app); -// export const auth = getAuth(app); - -// // For development purposes only -// connectFirestoreEmulator(db, "127.0.0.1", 8080); -// connectStorageEmulator(storage, "127.0.0.1", 9199); -// connectAuthEmulator(auth, "http://127.0.0.1:9099", { -// disableWarnings: true, -// }); import { initializeApp, getApps } from "firebase/app"; import { @@ -30,7 +7,6 @@ import { } from "firebase/auth"; import { getFirestore, connectFirestoreEmulator } from "firebase/firestore"; import { getStorage, connectStorageEmulator } from "firebase/storage"; -import dynamic from "next/dynamic"; export const firebaseConfig = { apiKey: process.env.NEXT_PUBLIC_FIREBASE_API_KEY, diff --git a/nextjs-end/src/lib/firebase/firestore.js b/nextjs-end/src/lib/firebase/firestore.js index dbead21a8..46225591e 100644 --- a/nextjs-end/src/lib/firebase/firestore.js +++ b/nextjs-end/src/lib/firebase/firestore.js @@ -51,7 +51,7 @@ const updateWithRating = async ( }); }; -export async function addReviewToRestaurant(restaurantId, review) { +export async function addReviewToRestaurant(db, restaurantId, review) { if (!restaurantId) { throw new Error("No restaurant ID has been provided."); }