简体   繁体   English

firebase setCustomUserClaims 执行不会在模拟器中结束

[英]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.

相关问题 Firebase 在 Android Studio 模拟器上不起作用 - Firebase doesn't work on Android Studio Emulator firebase/firestore/lite 不适用于 firebase 模拟器? - firebase/firestore/lite doesn't work with firebase emulator? Firebase 模拟器 - Spring 启动 - 名称为 [DEFAULT] 的 FirebaseApp 不存在 - Firebase Emulator - Spring boot - FirebaseApp with name [DEFAULT] doesn't exist Firebase docker 容器中的身份验证模拟器 UI 在本地主机上不起作用 - Firebase Authentication Emulator UI in docker container doesn't work on localhost Firebase 从真实设备接收数据,但不从仿真器接收数据....为什么? - Firebase receives data from real device but doesn't from an emulator....why? Firebase 存储模拟器不支持 getSignedUrl - Firebase Storage emulator does't support getSignedUrl Firebase @PropertyName 不起作用 - Firebase @PropertyName doesn't work Flutter:我的 Android 模拟器无法连接到 firebase 服务 - Flutter: My Android Emulator won't connect to firebase services 无法使用 firebase function 模拟器:内部错误 - Can't use firebase function emulator : INTERNAL ERROR 为什么 Local Firestore Emulator 对触发器没有反应? - Why Local Firestore Emulator doesn't react to the trigger?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM