Recebendo Dados Retornados de Funções Chamadas do Firebase
Estou brincando com as funções HTTPS de chamada no iOS. Eu criei e implantei a seguinte função:
export const generateLoginToken = functions.https.onCall((data, context) => {
const uid = data.user_id
if (!(typeof uid === 'string') || uid.length === 0) {
throw new functions.https.HttpsError('invalid-argument', 'The function must be called with one argument "user_id" ');
}
admin.auth().createCustomToken(uid)
.then((token) => {
console.log("Did create custom token:", token)
return { text: "some_data" };
}).catch((error) => {
console.log("Error creating custom token:", error)
throw new functions.https.HttpsError('internal', 'createCustomToken(uid) has failed for some reason')
})
})
Então eu chamo a função do meu aplicativo iOS assim:
let callParameters = ["user_id": userId]
self?.functions.httpsCallable("generateLoginToken").call(callParameters) { [weak self] (result, error) in
if let localError = self?.makeCallableFunctionError(error) {
single(SingleEvent.error(localError))
} else {
print("Result", result)
print("data", result?.data)
if let text = (result?.data as? [String: Any])?["text"] as? String {
single(SingleEvent.success(text))
} else {
let error = NSError.init(domain: "CallableFunctionError", code: 3, userInfo: ["info": "didn't find custom access token in the returned result"])
single(SingleEvent.error(error))
}
}
}
Posso ver nos logs que a função é invocada no servidor com os parâmetros corretos, mas não consigo obter os dados que estão sendo retornados da função de volta ao aplicativo. Parece que oresult.data
o valor énil
por alguma razão, mesmo que eureturn {text: "some_data"}
da função de nuvem.Por quê?