1

i use firebase cloudfunction for my ionic app but i need to change the method ( onRequest to onCall ) but i don't understand exactly what i need to change

This is my current firebase code:

import * as functions from 'firebase-functions'
import * as admin from 'firebase-admin'

const serviceAccount = require('../permissions.json')
const cors = require('cors')({ origin: true })

    

admin.initializeApp({
    credential: admin.credential.cert(serviceAccount),
    databaseURL: 'https://{'myUrl'}.firebaseio.com'
})

export const posts = functions.https.onRequest(async (request, response) => {
    const docs = await admin.firestore().collection('posts').orderBy('date', 'desc').get()
    cors(request, response, () => {})
    response.json(
        docs.docs.map((doc) => {
            return {
                postID: doc.id,
                ...doc.data()
            }
        })
    )
})

If anyone knows how I can change my code to make it work, It's super important i need to fix it quickly. Thank you in advance

123
  • 51
  • 7
  • Hello, what did you try? – Renaud Tarnec Aug 12 '20 at 12:31
  • Hello, i tried a lot of thing but every time i have'd the error code invalid_argument – 123 Aug 12 '20 at 13:24
  • It would be relevant to understand which layer is showing this "invalid_argument" code. This question https://stackoverflow.com/questions/51066434/firebase-cloud-functions-difference-between-onrequest-and-oncall could help you to understand the difference. Please keep in mind that The functions.https.onCall trigger automatically deserializes the request body and validates auth tokens. https://firebase.google.com/docs/functions/callable – Mario Aug 12 '20 at 22:22

0 Answers0