Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Next ssr update #247

Merged
merged 11 commits into from
Sep 13, 2023
7 changes: 6 additions & 1 deletion nextjs-end/src/app/actions.js
Original file line number Diff line number Diff line change
@@ -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"),

Expand Down
24 changes: 0 additions & 24 deletions nextjs-end/src/lib/firebase/firebase.js
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion nextjs-end/src/lib/firebase/firestore.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.");
}
Expand Down
Loading