Estoy creando un proyecto en nextjs y necesito guardar informacion de la apikey en env.local, pero estoy teniendo problemas al cargarlas. Este es el codigo que estoy utilizando para configurar firebase:
import firebase from "firebase/app";
import "firebase/firestore";
export async function getStaticProps() {
if (!firebase.apps.length){
firebase.initializeApp({
apiKey: process.env.APIKEY,
authDomain: process.env.AUTHDOMAIN,
databaseURL: process.env.DATABASEURL,
projectId: process.env.PROJECTID,
storageBucket: process.env.STORAGEBUCKET,
messagingSenderId: process.env.MESSAGINGSENDERID,
appId: process.env.APPID,
measurementId: process.env.MESSAGINGSENDERID
});
}else{
firebase.app();
}
}
getStaticProps();
let db = firebase.firestore();
db.settings({ timestampsInSnapshots: true });
export default db;
Cuando cargo directamente la apikey no hay problemas pero cuando la agrego con variables de entorno me lanza errores.
Este es el error:
@firebase/firestore: Firestore (8.2.2): Could not reach Cloud Firestore backend. Connection failed 1 times. Most recent error: FirebaseError: [code=not-found]: The project undefined does not exist or it does not contain an active Cloud Datastore or Cloud Firestore database. Please visit http://console.cloud.google.com to create a project or https://console.cloud.google.com/datastore/setup?project=undefined to add a Cloud Datastore or Cloud Firestore database. Note that Cloud Datastore or Cloud Firestore always have an associated App Engine app and this app must not be disabled. This typically indicates that your device does not have a healthy Internet connection at the moment. The client will operate in offline mode until it is able to successfully connect to the backend.