[英]firebase setCustomUserClaims execution doesn't end in emulator
I am trying to set a custom claim to an existing user in the emulator with the following code:我正在尝试使用以下代码为模拟器中的现有用户设置自定义声明:
exports.addAdmin = functions.https.onRequest((req, res) => {
admin.auth().setCustomUserClaims("ZZyxFu17eN8y6orw0tSQ8Y0vyPFS", { admin: true })
});
The logs tell me the the execution of the function started.日志告诉我 function 的执行开始了。 functions: Beginning execution of "addAdmin"
In the auth emulator I can see that the custom claim is successfully set to the user {"admin":true}
. functions: Beginning execution of "addAdmin"
在身份验证模拟器中,我可以看到自定义声明已成功设置为用户{"admin":true}
。 But the execution of the function doesn't end.但是 function 的执行并没有结束。
When I shutdown the emulator with CTRL+CI get the following logs functions: Waiting for all functions to finish...
.当我用 CTRL+CI 关闭模拟器时,得到以下日志functions: Waiting for all functions to finish...
Then after some minutes: functions: Functions emulator work queue did not empty before stopping ⚠ Your function was killed because it raised an unhandled error.
几分钟后: functions: Functions emulator work queue did not empty before stopping ⚠ Your function was killed because it raised an unhandled error.
What am I doing wrong here?我在这里做错了什么?
The setCustomUserClaims()
does end but you are not terminating the function itself. setCustomUserClaims()
确实结束了,但您并未终止 function 本身。 To terminate a HTTP function, you must return back a response.要终止 HTTP function,您必须返回响应。 Try:尝试:
exports.addAdmin = functions.https.onRequest(async (req, res) => {
await admin.auth().setCustomUserClaims("ZZyxFu17eN8y6orw0tSQ8Y0vyPFS", { admin: true })
return res.json({ message: "Claims updated" })
});
Checkout the documentation on terminating Cloud Functions and this video .查看有关 终止 Cloud Functions的文档和此视频。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.