Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

304
Views
Uso de las funciones de Google Cloud en Next.js (CSR)

Estoy tratando de usar las funciones de la nube de firebase en el proyecto Next.js, pero hay un error que no sé cómo solucionar.

firebase-config.js

 const firebaseConfig = { apiKey: '~~~', authDomain: '~~', projectId: '~~~', storageBucket: '~~~', messagingSenderId: '~~~~~', appId: '~~~~~', measurementId: '~~~~', }; const app = initializeApp(firebaseConfig); const db = getDatabase(app); const auth = getAuth(app); const functions = getFunctions(app); let analytics = null; if (app.name && typeof window !== 'undefined') { analytics = getAnalytics(app); } export { db, auth, functions, analytics };

Implementé la función de nube addMessage en mi base de fuego y llamé a esta función dentro de la /pages/friends

 import React, { useEffect, useState } from 'react' import { doc, getDoc } from 'firebase/firestore'; import { auth, functions } from '../../firebase-config'; import { getAuth, onAuthStateChanged, signOut } from 'firebase/auth'; const addMessage = functions.httpsCallable('addMessage'); export default function FriendsPage() { const [user, setUser] = useState(null); const [friendsList, setFriendsList] = useState(null); const currUser = auth.currentUser; const _onAuthStateChanged = (handler) => { if(!auth) return; onAuthStateChanged(auth, (user) => { //TODO(aaron) : bug fix if (user) { const uid = user.uid; console.log('AuthStateChanged', uid); //user is signed in handler(user); } else { // user is signed out } }); }; const addFriend = () => { addMessage().then((res)=>{ console.log(res); }) } useEffect(()=>{ setFriendsList() _onAuthStateChanged(setUser); console.log(user); }, []); if(!user){ return( <p>Loading...</p> ) } return ( <div> <h3>{user.first}s friends List</h3> <ul> <li>h</li> <li>h</li> <li>h</li> </ul> <buton onClick={addFriend}>Call functions</buton> </div> ) }

Pero aparece este mensaje de error. Creo que probablemente sea un problema cuando se cargan las funciones, ¿cómo puedo resolver esto?

 Server Error TypeError: _firebase_config__WEBPACK_IMPORTED_MODULE_2__.functions.httpsCallable is not a function This error happened while generating the page. Any console logs will be displayed in the terminal window. Source pages/friends/index.js (6:19) @ eval 4 | import { getAuth, onAuthStateChanged, signOut } from 'firebase/auth'; 5 | > 6 | const addMessage = functions.httpsCallable('addMessage'); | ^ 7 | 8 | export default function FriendsPage() { 9 | const [user, setUser] = useState(null);
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Estás mezclando la sintaxis v8 y v9 para las funciones invocables. Parece que está usando la v9 del SDK en su aplicación, no la v8. Cuando importa getFunctions, no obtiene un objeto que tenga un método llamado httpsCallable. Eso es lo que el mensaje de error intenta decirte. En su lugar, debe importar la función httpsCallable y pasarle el parámetro de función como argumento. Vea el ejemplo en la documentación para v9 .

 import { getFunctions, httpsCallable } from "firebase/functions"; const functions = getFunctions(); const addMessage = httpsCallable(functions, 'addMessage');
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!