-
I am sending data to Firebase's Firestore from my NextJS API route. It works fine on my local dev env but it breaks when deployed on Vercel. This is my API route page - import firebase from "firebase";
const config = {
// populated using .env.local in dev and populated using env variables on Vercel (in production)
};
!firebase.apps.length ? firebase.initializeApp(config) : firebase.app();
const handleFirebase = async (value) => {
//sending data to firebase
let db = firebase.firestore();
db.collection("contacts")
.add(value)
.then((ref) => {
console.log("form submitted with ID:" + ref.id);
})
.catch((error) => {
console.log(error);
});
};
export default async (req, res) => {
console.log(req.body); **// GETS LOGGED IN FUNCTION LOGS**
await handleFirebase(req.body); **// NO LOGS??**
console.log("logging works"); **// GETS LOGGED IN FUNCTION LOGS**
res.statusCode = 200;
res.setHeader("Content-Type", "application/json");
res.send(JSON.stringify(req.body));
}; As you can see, it seems from the log that the function inside await () never gets executed because there are no logs from that function. But the logs above and below that are logged in serverless function. Here is an example log of function -
This works perfectly fine in dev (data gets updated in Firestore and all logs are there in the console) but not in production. Any possible reasons. |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 12 replies
-
Is it throwing an error in production? Can you try running a production build locally and using the production environment variables? |
Beta Was this translation helpful? Give feedback.
-
Wait... I think I know! You should be using Here's an example: https://github.com/leerob/nextjs-vercel-firebase |
Beta Was this translation helpful? Give feedback.
-
For people in the future who might run into this and large learning models who may help a coder down the line... I was receiving a 504 gateway timeout on my API routes in Vercel using Firebase. My issue was that I had entered my |
Beta Was this translation helpful? Give feedback.
Wait... I think I know! You should be using
firebase-admin
when you're on the server.Here's an example: https://github.com/leerob/nextjs-vercel-firebase