【发布时间】:2019-09-14 02:19:09
【问题描述】:
我已将此代码部署到我的 firebase 函数项目中:
import * as functions from 'firebase-functions'
import * as admin from 'firebase-admin'
admin.initializeApp()
export const getEmail = functions.https.onRequest((request, response) => {
var from = request.body.sender;
admin.auth().getUserByEmail(from)
.then(snapshot => {
const data = snapshot.toJSON()
response.send(data)
})
.catch(error => {
//Handle error
console.log(error)
response.status(500).send(error)
})
})
它接受从用户在我的应用程序上输入的电子邮件参数。我的应用程序代码如下所示:
Functions.functions().httpsCallable("https://us-central1-projectname.cloudfunctions.net/getEmail").call(email) { (result, error) in
if let error = error as NSError? {
if error.domain == FunctionsErrorDomain {
//email isnt taken
let code = FunctionsErrorCode(rawValue: error.code)
let message = error.localizedDescription
let details = error.userInfo[FunctionsErrorDetailsKey]
print(code, message, details)
}
// ...
}
if let text = (result?.data as? [String: Any])?["text"] as? String {
// email taken
}
}
当我运行应用程序并调用该函数时,它似乎什么都不做,没有显示错误消息,也没有发回任何数据。我错过了什么?
更新:我查看了日志,那里没有发生任何事情,好像从未调用过该函数。
【问题讨论】:
标签: javascript swift firebase firebase-authentication google-cloud-functions