-
Notifications
You must be signed in to change notification settings - Fork 419
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
update to Next 14 and App Hosting (#287)
- Loading branch information
Showing
56 changed files
with
882 additions
and
624 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
lib/firebase/config.js | ||
.next/ | ||
.firebase/ | ||
.firebase/ | ||
node_modules/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
env: | ||
# Set this with firebase apphosting:secrets:set | ||
- variable: GEMINI_API_KEY | ||
secret: gemini-api-key | ||
# Get these values from the Firebase console | ||
- variable: NEXT_PUBLIC_FIREBASE_API_KEY | ||
value: TODO | ||
- variable: NEXT_PUBLIC_FIREBASE_AUTH_DOMAIN | ||
value: TODO | ||
- variable: NEXT_PUBLIC_FIREBASE_PROJECT_ID | ||
value: TODO | ||
- variable: NEXT_PUBLIC_FIREBASE_STORAGE_BUCKET | ||
value: TODO | ||
- variable: NEXT_PUBLIC_FIREBASE_MESSAGING_SENDER_ID | ||
value: TODO | ||
- variable: NEXT_PUBLIC_FIREBASE_APP_ID | ||
value: TODO |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { initializeApp } from "firebase/app"; | ||
import { getAuth, getIdToken } from "firebase/auth"; | ||
import { getInstallations, getToken } from "firebase/installations"; | ||
|
||
// this is set during install | ||
let firebaseConfig; | ||
|
||
self.addEventListener('install', event => { | ||
// extract firebase config from query string | ||
const serializedFirebaseConfig = new URL(location).searchParams.get('firebaseConfig'); | ||
|
||
if (!serializedFirebaseConfig) { | ||
throw new Error('Firebase Config object not found in service worker query string.'); | ||
} | ||
|
||
firebaseConfig = JSON.parse(serializedFirebaseConfig); | ||
console.log("Service worker installed with Firebase config", firebaseConfig); | ||
}); | ||
|
||
self.addEventListener("fetch", (event) => { | ||
const { origin } = new URL(event.request.url); | ||
if (origin !== self.location.origin) return; | ||
event.respondWith(fetchWithFirebaseHeaders(event.request)); | ||
}); | ||
|
||
async function fetchWithFirebaseHeaders(request) { | ||
const app = initializeApp(firebaseConfig); | ||
const auth = getAuth(app); | ||
const installations = getInstallations(app); | ||
const headers = new Headers(request.headers); | ||
const [authIdToken, installationToken] = await Promise.all([ | ||
getAuthIdToken(auth), | ||
getToken(installations), | ||
]); | ||
headers.append("Firebase-Instance-ID-Token", installationToken); | ||
if (authIdToken) headers.append("Authorization", `Bearer ${authIdToken}`); | ||
const newRequest = new Request(request, { headers }); | ||
return await fetch(newRequest); | ||
} | ||
|
||
async function getAuthIdToken(auth) { | ||
await auth.authStateReady(); | ||
if (!auth.currentUser) return; | ||
return await getIdToken(auth.currentUser); | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,37 @@ | ||
import Restaurant from "@/src/components/Restaurant.jsx"; | ||
import { useUser } from "@/src/lib/firebase/auth"; | ||
import { Suspense } from "react"; | ||
import { getRestaurantById } from "@/src/lib/firebase/firestore.js"; | ||
import { getAuthenticatedAppForUser, getAuthenticatedAppForUser as getUser } from "@/src/lib/firebase/serverApp.js"; | ||
import ReviewsList, { | ||
ReviewsListSkeleton, | ||
} from "@/src/components/Reviews/ReviewsList"; | ||
import { | ||
getRestaurantById, | ||
getReviewsByRestaurantId, | ||
} from "@/src/lib/firebase/firestore.js"; | ||
import { | ||
getAuthenticatedAppForUser | ||
} from "@/src/lib/firebase/firebase.js"; | ||
|
||
|
||
|
||
export const dynamic = "force-dynamic"; | ||
GeminiSummary, | ||
GeminiSummarySkeleton, | ||
} from "@/src/components/Reviews/ReviewSummary"; | ||
import { getFirestore } from "firebase/firestore"; | ||
|
||
export default async function Home({ params }) { | ||
// This is a server component, we can access URL | ||
// parameters via Next.js and download the data | ||
// we need for this page | ||
const restaurant = await getRestaurantById(params.id); | ||
const reviews = await getReviewsByRestaurantId(params.id); | ||
const { currentUser } = await getAuthenticatedAppForUser() | ||
const { currentUser } = await getUser(); | ||
const {firebaseServerApp} = await getAuthenticatedAppForUser(); | ||
const restaurant = await getRestaurantById(getFirestore(firebaseServerApp), params.id); | ||
|
||
return ( | ||
<main className="main__restaurant"> | ||
<Restaurant | ||
id={params.id} | ||
initialRestaurant={restaurant} | ||
initialReviews={reviews} | ||
initialUserId={currentUser?.uid || ""} | ||
/> | ||
</main> | ||
); | ||
return ( | ||
<main className="main__restaurant"> | ||
<Restaurant | ||
id={params.id} | ||
initialRestaurant={restaurant} | ||
initialUserId={currentUser?.uid || ""} | ||
> | ||
<Suspense fallback={<GeminiSummarySkeleton />}> | ||
<GeminiSummary restaurantId={params.id} /> | ||
</Suspense> | ||
</Restaurant> | ||
<Suspense | ||
fallback={<ReviewsListSkeleton numReviews={restaurant.numRatings} />} | ||
> | ||
<ReviewsList restaurantId={params.id} userId={currentUser?.uid || ""} /> | ||
</Suspense> | ||
</main> | ||
); | ||
} |
Oops, something went wrong.