我正在使用 android studio 开发一个基于角色的应用程序,因为我的项目需要管理员权限来创建用户和删除用户我为我的项目使用了 firebase admin sdk。我试图删除多个帐户,但我遇到了问题。响应返回无效的 json 对象。正如在我的代码中,我试图处理可能的错误。但是,响应仍然返回无效的 json 对象。 见下文索引.js exports.deleteUser = functions.https.onCall(async (data,context) => {try { if(!context.auth) { throw new AuthenticationError('Kimlik Doğrulaması Yapılmamış'); } const uids = JSON.parse(data); console.log(uids); const callerUid = context.auth.uid; const callerUser = await admin.auth().getUser(callerUid); if(!callerUser.customClaims.admin && !callerUser.customClaims.superadmin) { throw new NotAnAdminError('Bu işlemi sadece yöneticiler gerçekleştirebilir'); } const reference = admin.firestore().collection("Users"); const res = await admin.auth().deleteUsers(uids); res.errors.forEach(element => console.log(element)); const successes = res.successCount; const fails = res.failureCount; console.log(fails); console.log(successes); if(fails===0) { await uids.forEach(element => reference.doc(element).delete()); return {result:successes+' Öğrenci Silindi!'}; }else { throw new functions.https.HttpsError('Silme Hatası','Bilinmeyen hata, silinemeyen öğrenci sayısı: '+fails); }} catch(error) { if(error.type === 'NotAnAdminError') { throw new functions.https.HttpsError('Bu işlemi yapma yetkiniz yok.',error.message); }else if(error.type === 'AuthenticationError') { throw new functions.https.HttpsError('Kimlik Hatası',error.message); }else { throw new functions.https.HttpsError('internal ERROR from catch block',error.message); } }});
添加回答
举报
0/150
提交
取消