how to use firebase
Unanswered
Schneider’s Smooth-fronted Caima… posted this in #help-forum
Schneider’s Smooth-fronted CaimanOP
import { getFirestore, collection, addDoc } from "firebase/firestore";
import app from "../../firebase";
const firestore = getFirestore(app);
export async function POSt(req, res) {
if (req.method === "POST") {
const { data } = req.body;
try {
const docRef = await addDoc(collection(firestore, "votes"), data);
res.status(200).json({ id: docRef.id, ...data });
} catch (error) {
res.status(500).json({ error: "Failed to add document" });
}
} else {
res.status(405).json({ error: "Method not allowed" });
}
}
this code doesnt work (i have a firebase.js with configs etc and env) my app uses app router, and I think nextresponse or response be used here idk how please help i need a urgent help
import app from "../../firebase";
const firestore = getFirestore(app);
export async function POSt(req, res) {
if (req.method === "POST") {
const { data } = req.body;
try {
const docRef = await addDoc(collection(firestore, "votes"), data);
res.status(200).json({ id: docRef.id, ...data });
} catch (error) {
res.status(500).json({ error: "Failed to add document" });
}
} else {
res.status(405).json({ error: "Method not allowed" });
}
}
this code doesnt work (i have a firebase.js with configs etc and env) my app uses app router, and I think nextresponse or response be used here idk how please help i need a urgent help
2 Replies
Schneider’s Smooth-fronted CaimanOP
and also how to add firebase please
Schneider’s Smooth-fronted CaimanOP
anyone