颤振和 Firebase 函数:类型错误:无法读取未定义的属性'token'



这是我在被揭穿的中得到的错误

[VERBOSE-2:ui_dart_state.cc(186)] Unhandled Exception: [firebase_functions/3840] The data couldn’t be read because it isn’t in the correct format.
#0      catchPlatformException
package:cloud_functions_platform_interface/…/utils/exception.dart:21
#1      _rootRunBinary (dart:async/zone.dart:1378:47)
#2      _CustomZone.runBinary (dart:async/zone.dart:1272:19)
#3      _FutureListener.handleError (dart:async/future_impl.dart:166:20)
#4      Future._propagateToListeners.handleError (dart:async/future_impl.dart:716:47)
#5      Future._propagateToListeners (dart:async/future_impl.dart:737:24)
#6      Future._completeError (dart:async/future_impl.dart:547:5)
#7      _completeOnAsyncError (dart:async-patch/async_patch.dart:264:13)

Fuunctions日志出现以下错误:

Unhandled error TypeError: Cannot read property 'token' of undefined
at /workspace/index.js:19:33
at func (/workspace/node_modules/firebase-functions/lib/providers/https.js:273:32)
at processTicksAndRejections (internal/process/task_queues.js:97:5) 

实际功能:

const functions = require("firebase-functions");
const firebaseTools = require("firebase-tools");
exports.delMessages = functions.runWith({
timeoutSeconds: 250,
memory: "512MB",
}).https.onCall(async (data, context) => {
if (!(context.auth && context.auth.token && context.auth.token.admin)) {
throw new functions.https.HttpsError(
"permission-denied", "user must be logged in"
);
}
const path = data.path;
await firebaseTools.firestore.delete(path, {
project: process.env.GCLOUD_PROJECT,
recursive: true,
yes: true,
token: functions.config().fb.token,
});
return {
path: path,
};
});

还有颤动调用:

import 'package:flutter/material.dart';
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:cloud_functions/cloud_functions.dart';
import './message.dart';
class ChatList extends StatefulWidget {
ChatList({
Key key,
}) : super(key: key);
@override
_ChatListState createState() => _ChatListState();
}
class _ChatListState extends State<ChatList> {
Future<void> runDelMessage(String msgId) async {
final functions = FirebaseFunctions.instance;
HttpsCallable callable = functions.httpsCallable('delMessage');
await callable({'path': 'chat/$msgId'});
}
@override
Widget build(BuildContext context) {
return StreamBuilder(
stream: FirebaseFirestore.instance
.collection('chat')
.orderBy(
'createdAt',
descending: true,
)
.snapshots(),
builder: (ctx, AsyncSnapshot<QuerySnapshot> chatSnapshot) {
if (chatSnapshot.connectionState == ConnectionState.waiting) {
return Expanded(
child: Center(
child: CircularProgressIndicator(),
),
);
}
if (chatSnapshot.hasError) {
print('there was an error');
}
final chatDocs = chatSnapshot.data.docs;
final int chatLength = chatDocs.length;
//final displayDocs = chatDocs.sublist(chatLength - 30);
if (chatLength > 50) {
runDelMessage(chatDocs[chatLength - 1].id);
}
return Expanded(
child: ListView.builder(
//controller: _scrollController,
reverse: true,
itemCount: chatLength,
itemBuilder: (context, index) {
return Message(
chatDocs[index].data(),
key: ValueKey(chatDocs[index].id),
);
},
),
);
},
);
}
}

我已经查看了官方的FlutterFire文档,代码主要是Firebase函数示例的副本。该代码表明用户令牌将由SDK处理。否则我该怎么办?

谢谢

问题是,如果Map只有一个键,那么请求应该是List。

令牌还需要作为数据传递。

相关内容

最新更新