Skip to content

Commit eed82bf

Browse files
committed
apis added
1 parent 14d5a5b commit eed82bf

File tree

4 files changed

+33
-17
lines changed

4 files changed

+33
-17
lines changed

firebase/config.js

+7-7
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ import { getAnalytics } from "firebase/analytics";
33
import { collection, getFirestore } from "firebase/firestore";
44

55
export const firebaseConfig = {
6-
apiKey: process.env.NEXT_PUBLIC_API_KEY,
7-
authDomain: process.env.NEXT_PUBLIC_AUTH_DOMAIN,
8-
projectId: process.env.NEXT_PUBLIC_PROJECT_ID,
9-
storageBucket: process.env.NEXT_PUBLIC_STORAGE_BUCKET,
10-
messagingSenderId: process.env.NEXT_PUBLIC_MESSAGING_SENDER_ID,
11-
appId: process.env.NEXT_PUBLIC_APP_ID,
12-
measurementId: process.env.NEXT_PUBLIC_MEASUREMENT_ID,
6+
apiKey: process.env.FIREBASE_API_KEY,
7+
authDomain: process.env.FIREBASE_AUTH_DOMAIN,
8+
projectId: process.env.FIREBASE_PROJECT_ID,
9+
storageBucket: process.env.FIREBASE_STORAGE_BUCKET,
10+
messagingSenderId: process.env.FIREBASE_MESSAGING_SENDER_ID,
11+
appId: process.env.FIREBASE_APP_ID,
12+
measurementId: process.env.FIREBASE_MEASUREMENT_ID,
1313
};
1414

1515
const app = initializeApp(firebaseConfig);

pages/api/hello.js

-5
This file was deleted.

pages/api/increment.js

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Next.js API route support: https://nextjs.org/docs/api-routes/introduction
2+
3+
import { db } from "@/firebase/config";
4+
import { doc, getDoc, setDoc, increment, FieldValue } from "firebase/firestore";
5+
6+
export default async function handler(req, res) {
7+
try {
8+
const docRef = doc(db, "soladd", "addresses_found");
9+
10+
await setDoc(docRef, {
11+
curr: (await getDoc(docRef)).data().curr + 1,
12+
});
13+
14+
res.status(200).json({ status: "incremented successfully" });
15+
} catch (err) {
16+
console.log(err);
17+
res.status(500).json({ status: "something went wrong" });
18+
}
19+
}

pages/index.js

+7-5
Original file line numberDiff line numberDiff line change
@@ -100,12 +100,14 @@ export default function Home() {
100100

101101
const incrementAddressesFound = async () => {
102102
try {
103-
console.log("hello");
104-
const docRef = doc(db, "soladd", "addresses_found");
103+
// console.log("hello");
104+
const res = await fetch("/api/increment");
105105

106-
await setDoc(docRef, {
107-
curr: (await getDoc(docRef)).data().curr + 1,
108-
});
106+
// const docRef = doc(db, "soladd", "addresses_found");
107+
108+
// await setDoc(docRef, {
109+
// curr: (await getDoc(docRef)).data().curr + 1,
110+
// });
109111
} catch (err) {
110112
console.log(err);
111113
}

0 commit comments

Comments
 (0)