Skip to content

Commit

Permalink
fix: update nextjs-start (#252)
Browse files Browse the repository at this point in the history
  • Loading branch information
HYACCCINT authored Sep 20, 2023
1 parent e96ac76 commit cacd6b8
Show file tree
Hide file tree
Showing 47 changed files with 680 additions and 282 deletions.
Binary file modified .DS_Store
Binary file not shown.
Binary file added nextjs-end/.DS_Store
Binary file not shown.
28 changes: 0 additions & 28 deletions nextjs-end/src/lib/firebase/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,31 +27,3 @@ export async function signOut() {
console.error("Error signing out with Google", error);
}
}

// export function useUser(auth) {
// const [user, setUser] = useState();
// const router = useRouter();

// useEffect(() => {
// const unsubscribe = onAuthStateChanged(auth, (authUser) => {
// setUser(authUser);
// });

// return () => unsubscribe();
// // eslint-disable-next-line react-hooks/exhaustive-deps
// }, []);

// useEffect(() => {
// onAuthStateChanged(auth, (authUser) => {
// if (user === undefined) return;

// // refresh when user changed to ease testing
// if (user?.email !== authUser?.email) {
// router.refresh();
// }
// });
// // eslint-disable-next-line react-hooks/exhaustive-deps
// }, [user]);

// return null;
// }
10 changes: 2 additions & 8 deletions nextjs-end/src/lib/firebase/firebase.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import {
connectAuthEmulator,
signInWithCustomToken,
} from "firebase/auth";
import { getFirestore, connectFirestoreEmulator } from "firebase/firestore";
import { getStorage, connectStorageEmulator } from "firebase/storage";
import { getFirestore } from "firebase/firestore";
import { getStorage } from "firebase/storage";

export const firebaseConfig = {
apiKey: process.env.NEXT_PUBLIC_FIREBASE_API_KEY,
Expand All @@ -23,12 +23,6 @@ export const auth = getAuth(firebaseApp);
export const db = getFirestore(firebaseApp);
export const storage = getStorage(firebaseApp);

// 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,
// });

export async function getAuthenticatedAppForUser(session = null) {

Expand Down
Binary file added nextjs-start/.DS_Store
Binary file not shown.
6 changes: 6 additions & 0 deletions nextjs-start/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
NEXT_PUBLIC_FIREBASE_API_KEY=""
NEXT_PUBLIC_FIREBASE_AUTH_DOMAIN=""
NEXT_PUBLIC_FIREBASE_PROJECT_ID=""
NEXT_PUBLIC_FIREBASE_STORAGE_BUCKET=""
NEXT_PUBLIC_FIREBASE_MESSAGING_SENDER_ID=""
NEXT_PUBLIC_FIREBASE_APP_ID=""
4 changes: 3 additions & 1 deletion nextjs-start/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
.next/
lib/firebase/config.js
.next/
.firebase/
107 changes: 0 additions & 107 deletions nextjs-start/components/Restaurant.jsx

This file was deleted.

56 changes: 56 additions & 0 deletions nextjs-start/firebase.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
{
"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"
}
}
117 changes: 117 additions & 0 deletions nextjs-start/firestore.indexes.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
{
"indexes": [
{
"collectionGroup": "restaurants",
"queryScope": "COLLECTION",
"fields": [
{
"fieldPath": "category",
"order": "ASCENDING"
},
{
"fieldPath": "avgRating",
"order": "DESCENDING"
}
]
},
{
"collectionGroup": "restaurants",
"queryScope": "COLLECTION",
"fields": [
{
"fieldPath": "category",
"order": "ASCENDING"
},
{
"fieldPath": "numRatings",
"order": "DESCENDING"
}
]
},
{
"collectionGroup": "restaurants",
"queryScope": "COLLECTION",
"fields": [
{
"fieldPath": "category",
"order": "ASCENDING"
},
{
"fieldPath": "price",
"order": "ASCENDING"
}
]
},
{
"collectionGroup": "restaurants",
"queryScope": "COLLECTION",
"fields": [
{
"fieldPath": "city",
"order": "ASCENDING"
},
{
"fieldPath": "avgRating",
"order": "DESCENDING"
}
]
},
{
"collectionGroup": "restaurants",
"queryScope": "COLLECTION",
"fields": [
{
"fieldPath": "city",
"order": "ASCENDING"
},
{
"fieldPath": "numRatings",
"order": "DESCENDING"
}
]
},
{
"collectionGroup": "restaurants",
"queryScope": "COLLECTION",
"fields": [
{
"fieldPath": "city",
"order": "ASCENDING"
},
{
"fieldPath": "price",
"order": "ASCENDING"
}
]
},
{
"collectionGroup": "restaurants",
"queryScope": "COLLECTION",
"fields": [
{
"fieldPath": "price",
"order": "ASCENDING"
},
{
"fieldPath": "avgRating",
"order": "DESCENDING"
}
]
},
{
"collectionGroup": "restaurants",
"queryScope": "COLLECTION",
"fields": [
{
"fieldPath": "price",
"order": "ASCENDING"
},
{
"fieldPath": "numRatings",
"order": "DESCENDING"
}
]
}
],
"fieldOverrides": []
}
36 changes: 36 additions & 0 deletions nextjs-start/firestore.rules
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
rules_version = '2';
service cloud.firestore {

// Determine if the value of the field "key" is the same
// before and after the request.
function unchanged(key) {
return (key in resource.data)
&& (key in request.resource.data)
&& (resource.data[key] == request.resource.data[key]);
}

match /databases/{database}/documents {
// Restaurants:
// - Authenticated user can read
// - Authenticated user can create/update (for demo purposes only)
// - Updates are allowed if no fields are added and name is unchanged
// - Deletes are not allowed (default)
match /restaurants/{restaurantId} {
allow read;
allow create: if request.auth != null;
allow update: if request.auth != null
&& unchanged("name");

// Ratings:
// - Authenticated user can read
// - Authenticated user can create if userId matches
// - Deletes and updates are not allowed (default)
match /ratings/{ratingId} {
allow read;
allow create: if request.auth != null;
allow update: if request.auth != null
&& request.resource.data.userId == request.auth.uid;
}
}
}
}
1 change: 1 addition & 0 deletions nextjs-start/functions/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules/
Loading

0 comments on commit cacd6b8

Please sign in to comment.