Is there a way to obtain a Firebase Auth token using the onCall function in the Cloud Functions emulator?

196 views Asked by At

I'm a beginner in Firebase Functions and I'm trying to get the user's token authenticated by calling the onCall function. I wonder if there is any way to get the token for this function

Index.js

const functions = require('firebase-functions');
exports.chat = require("./api/chat")

Chat.js

exports.init = functions.https.onCall(async (data, context) => {
const key = JSON.parse(data)
console.log(`Starting chat listener to room: ${key}`)

admin.database().ref(`main/${key}/chat`).on('child_added', (snapshot) => {
    chat = snapshot.val()
    //Send obj chat to client
    //admin.messaging().send('test')
  })
})

Client.class

chatInit(roomId).addOnCompleteListener(task -> {
            if (task.isSuccessful()) {
                Log.e("test", ""+task.getResult());
                decodeOnline();
            }
        });

 public Task<String> chatInit(String key) {
    return zFunctions.getHttpsCallable("chat-init")
            .call(key)
            .continueWith(task -> (String) task.getResult().getData());
}

Note: I'm performing the tests on Firebase Emulators

0

There are 0 answers