From 1eb300f86a09abcb9cbfd32b0c822957327ba2dc Mon Sep 17 00:00:00 2001 From: Umar Hansa Date: Wed, 27 Sep 2023 14:40:52 +0100 Subject: [PATCH] Small fixes (#253) --- nextjs-start/firebase.json | 92 ++++++++++-------------- nextjs-start/functions/.gitignore | 1 - nextjs-start/functions/index.js | 19 ----- nextjs-start/functions/package.json | 23 ------ nextjs-start/src/app/actions.js | 13 +--- nextjs-start/src/lib/firebase/storage.js | 27 ++----- 6 files changed, 44 insertions(+), 131 deletions(-) delete mode 100644 nextjs-start/functions/.gitignore delete mode 100644 nextjs-start/functions/index.js delete mode 100644 nextjs-start/functions/package.json diff --git a/nextjs-start/firebase.json b/nextjs-start/firebase.json index 069dcbedb..0f0ea2b9e 100644 --- a/nextjs-start/firebase.json +++ b/nextjs-start/firebase.json @@ -1,56 +1,40 @@ { - "emulators": { - "auth": { - "port": 9099 - }, - "functions": { - "port": 5001 - }, - "firestore": { - "port": 8080 - }, - "database": { - "port": 9000 - }, - "storage": { - "port": 9199 - }, - "ui": { - "enabled": true - }, - "singleProjectMode": true, - "hosting": { - "port": 5000 - } - }, - "functions": [ - { - "source": "functions", - "codebase": "default", - "ignore": [ - "node_modules", - ".git", - "firebase-debug.log", - "firebase-debug.*.log" - ] - } - ], - "firestore": { - "rules": "firestore.rules", - "indexes": "firestore.indexes.json" - }, - "hosting": { - "source": ".", - "ignore": [ - "firebase.json", - "**/.*", - "**/node_modules/**" - ], - "frameworksBackend": { - "region": "us-central1" - } - }, - "storage": { - "rules": "storage.rules" - } + "emulators": { + "auth": { + "port": 9099 + }, + "functions": { + "port": 5001 + }, + "firestore": { + "port": 8080 + }, + "database": { + "port": 9000 + }, + "storage": { + "port": 9199 + }, + "ui": { + "enabled": true + }, + "singleProjectMode": true, + "hosting": { + "port": 5000 + } + }, + "firestore": { + "rules": "firestore.rules", + "indexes": "firestore.indexes.json" + }, + "hosting": { + "source": ".", + "ignore": ["firebase.json", "**/.*", "**/node_modules/**"], + "frameworksBackend": { + "region": "us-central1" + } + }, + "storage": { + "rules": "storage.rules" + } } diff --git a/nextjs-start/functions/.gitignore b/nextjs-start/functions/.gitignore deleted file mode 100644 index 40b878db5..000000000 --- a/nextjs-start/functions/.gitignore +++ /dev/null @@ -1 +0,0 @@ -node_modules/ \ No newline at end of file diff --git a/nextjs-start/functions/index.js b/nextjs-start/functions/index.js deleted file mode 100644 index e81477f69..000000000 --- a/nextjs-start/functions/index.js +++ /dev/null @@ -1,19 +0,0 @@ -/** - * Import function triggers from their respective submodules: - * - * const {onCall} = require("firebase-functions/v2/https"); - * const {onDocumentWritten} = require("firebase-functions/v2/firestore"); - * - * See a full list of supported triggers at https://firebase.google.com/docs/functions - */ - -const {onRequest} = require("firebase-functions/v2/https"); -const logger = require("firebase-functions/logger"); - -// Create and deploy your first functions -// https://firebase.google.com/docs/functions/get-started - -// exports.helloWorld = onRequest((request, response) => { -// logger.info("Hello logs!", {structuredData: true}); -// response.send("Hello from Firebase!"); -// }); diff --git a/nextjs-start/functions/package.json b/nextjs-start/functions/package.json deleted file mode 100644 index 392196b98..000000000 --- a/nextjs-start/functions/package.json +++ /dev/null @@ -1,23 +0,0 @@ -{ - "name": "functions", - "description": "Cloud Functions for Firebase", - "scripts": { - "serve": "firebase emulators:start --only functions", - "shell": "firebase functions:shell", - "start": "npm run shell", - "deploy": "firebase deploy --only functions", - "logs": "firebase functions:log" - }, - "engines": { - "node": "18" - }, - "main": "index.js", - "dependencies": { - "firebase-admin": "^11.8.0", - "firebase-functions": "^4.3.1" - }, - "devDependencies": { - "firebase-functions-test": "^3.1.0" - }, - "private": true -} diff --git a/nextjs-start/src/app/actions.js b/nextjs-start/src/app/actions.js index ec7b21af1..b65d82006 100644 --- a/nextjs-start/src/app/actions.js +++ b/nextjs-start/src/app/actions.js @@ -7,15 +7,6 @@ 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) { - const { app } = await getAuthenticatedAppForUser(); - const db = getFirestore(app); - await addReviewToRestaurant(db, data.get("restaurantId"), { - text: data.get("text"), - rating: data.get("rating"), - - // This came from a hidden form field - userId: data.get("userId"), - }); -} +// Replace the function below +export async function handleReviewFormSubmission(data) {} diff --git a/nextjs-start/src/lib/firebase/storage.js b/nextjs-start/src/lib/firebase/storage.js index f9da55645..96b2299bb 100644 --- a/nextjs-start/src/lib/firebase/storage.js +++ b/nextjs-start/src/lib/firebase/storage.js @@ -4,27 +4,8 @@ import { storage } from "@/src/lib/firebase/firebase"; import { updateRestaurantImageReference } from "@/src/lib/firebase/firestore"; -export async function updateRestaurantImage(restaurantId, image) { - try { - if (!restaurantId) - throw new Error("No restaurant ID has been provided."); +// Replace the two functions below +export async function updateRestaurantImage(restaurantId, image) {} - if (!image || !image.name) - throw new Error("A valid image has not been provided."); - - const publicImageUrl = await uploadImage(restaurantId, image); - await updateRestaurantImageReference(restaurantId, publicImageUrl); - - return publicImageUrl; - } catch (error) { - console.error("Error processing request:", error); - } -} - -async function uploadImage(restaurantId, image) { - const filePath = `images/${restaurantId}/${image.name}`; - const newImageRef = ref(storage, filePath); - await uploadBytesResumable(newImageRef, image); - - return await getDownloadURL(newImageRef); -} +async function uploadImage(restaurantId, image) {} +// Replace the two functions above