【发布时间】:2019-12-16 20:07:21
【问题描述】:
我正在尝试将国际象棋游戏保存到 Firebase。我有一个反应应用程序,当我使用 set() 方法时,我得到了这个错误:
PERMISSION_DENIED: Permission denied
(anonymous function)
C:/Users/Hello/Documents/Dev/chess/src/core/Repo.ts:620
617 | let message = code;
618 | if (errorReason) message += ': ' + errorReason;
619 |
> 620 | const error = new Error(message);
| ^ 621 | (error as any).code = code;
622 | callback(error);
623 | }
View compiled
exceptionGuard
C:/Users/Hello/Documents/Dev/chess/src/core/util/util.ts:574
571 | */
572 | export const exceptionGuard = function(fn: () => void) {
573 | try {
> 574 | fn();
575 | } catch (e) {
576 | // Re-throw exception when it's safe.
577 | setTimeout(function() {
View compiled
Repo.callOnCompleteCallback
C:/Users/Hello/Documents/Dev/chess/src/core/Repo.ts:612
609 | errorReason?: string | null
610 | ) {
611 | if (callback) {
> 612 | exceptionGuard(function() {
| ^ 613 | if (status == 'ok') {
614 | callback(null);
615 | } else {
View compiled
(anonymous function)
C:/Users/Hello/Documents/Dev/chess/src/core/Repo.ts:342
339 | !success
340 | );
341 | this.eventQueue_.raiseEventsForChangedPath(path, clearEvents);
> 342 | this.callOnCompleteCallback(onComplete, status, errorReason);
| ^ 343 | }
344 | );
345 | const affectedPath = this.abortTransactions_(path);
View compiled
(anonymous function)
C:/Users/Hello/Documents/Dev/chess/src/core/PersistentConnection.ts:522
519 | this.outstandingPuts_ = [];
520 | }
521 |
> 522 | if (onComplete)
| ^ 523 | onComplete(message[/*status*/ 's'], message[/* data */ 'd']);
524 | });
525 | }
View compiled
PersistentConnection.onDataMessage_
C:/Users/Hello/Documents/Dev/chess/src/core/PersistentConnection.ts:554
551 | const onResponse = this.requestCBHash_[reqNum];
552 | if (onResponse) {
553 | delete this.requestCBHash_[reqNum];
> 554 | onResponse(message[/*body*/ 'b']);
| ^ 555 | }
556 | } else if ('error' in message) {
557 | throw 'A server-side error has occurred: ' + message['error'];
View compiled
Connection.onDataMessage_
C:/Users/Hello/Documents/Dev/chess/src/realtime/Connection.ts:317
314 | this.onPrimaryResponse_();
315 |
316 | // We don't do anything with data messages, just kick them up a level
> 317 | this.onMessage_(message);
| ^ 318 | }
319 |
320 | private onPrimaryResponse_() {
View compiled
Connection.onPrimaryMessageReceived_
C:/Users/Hello/Documents/Dev/chess/src/realtime/Connection.ts:309
306 | if (layer == 'c') {
307 | this.onControl_(data);
308 | } else if (layer == 'd') {
> 309 | this.onDataMessage_(data);
| ^ 310 | }
311 | }
312 |
View compiled
WebSocketConnection.onMessage
C:/Users/Hello/Documents/Dev/chess/src/realtime/Connection.ts:205
202 | return (message: object) => {
203 | if (this.state_ != RealtimeState.DISCONNECTED) {
204 | if (conn === this.rx_) {
> 205 | this.onPrimaryMessageReceived_(message);
| ^ 206 | } else if (conn === this.secondaryConn_) {
207 | this.onSecondaryMessageReceived_(message);
208 | } else {
View compiled
WebSocketConnection.appendFrame_
C:/Users/Hello/Documents/Dev/chess/src/realtime/WebSocketConnection.ts:273
270 | const jsonMess = jsonEval(fullMess) as object;
271 |
272 | //handle the message
> 273 | this.onMessage(jsonMess);
| ^ 274 | }
275 | }
276 |
View compiled
WebSocketConnection.handleIncomingFrame
C:/Users/Hello/Documents/Dev/chess/src/realtime/WebSocketConnection.ts:326
323 | // try to parse out a frame count, otherwise, assume 1 and process it
324 | const remainingData = this.extractFrameCount_(data);
325 | if (remainingData !== null) {
> 326 | this.appendFrame_(remainingData);
| ^ 327 | }
328 | }
329 | }
View compiled
WebSocket.mySock.onmessage
C:/Users/Hello/Documents/Dev/chess/src/realtime/WebSocketConnection.ts:193
190 | };
191 |
192 | this.mySock.onmessage = (m: object) => {
> 193 | this.handleIncomingFrame(m);
| ^ 194 | };
195 |
196 | this.mySock.onerror = (e: any) => {
View compiled
This screen is visible only in development. It will not appear if the app crashes in production.
Open your browser’s developer console to further inspect this error.
控制台报错:
Repo.ts:620 Uncaught (in promise) Error: PERMISSION_DENIED: Permission denied
at Repo.ts:620
at exceptionGuard (util.ts:574)
at Repo.callOnCompleteCallback (Repo.ts:612)
at Repo.ts:342
at PersistentConnection.ts:522
at PersistentConnection.onDataMessage_ (PersistentConnection.ts:554)
at Connection.onDataMessage_ (Connection.ts:317)
at Connection.onPrimaryMessageReceived_ (Connection.ts:309)
at WebSocketConnection.onMessage (Connection.ts:205)
at WebSocketConnection.appendFrame_ (WebSocketConnection.ts:273)
at WebSocketConnection.handleIncomingFrame (WebSocketConnection.ts:326)
at WebSocket.mySock.onmessage (WebSocketConnection.ts:193)
(anonymous) @ Repo.ts:620
exceptionGuard @ util.ts:574
Repo.callOnCompleteCallback @ Repo.ts:612
(anonymous) @ Repo.ts:342
(anonymous) @ PersistentConnection.ts:522
PersistentConnection.onDataMessage_ @ PersistentConnection.ts:554
Connection.onDataMessage_ @ Connection.ts:317
Connection.onPrimaryMessageReceived_ @ Connection.ts:309
(anonymous) @ Connection.ts:205
WebSocketConnection.appendFrame_ @ WebSocketConnection.ts:273
WebSocketConnection.handleIncomingFrame @ WebSocketConnection.ts:326
mySock.onmessage @ WebSocketConnection.ts:193
我正在阅读我需要更改规则以删除开发身份验证,但这似乎不起作用:
以下是相关代码:
import firebase from '../firebase.js';
const gamesRef = firebase.database().ref('game').push(); //creates node, returns hash id
const game = {
pieces:newPieces,
}
gamesRef.set(game); // pushes to firebase
还有我的 firebase.js:
import firebase from 'firebase'
const config = {
apiKey: "AIzaSyDQKeczO19-gE5Dpvc_NSRkwZWQeasn08o",
authDomain: "chess-b0d2c.firebaseapp.com",
databaseURL: "https://chess-b0d2c.firebaseio.com",
projectId: "chess-b0d2c",
storageBucket: "chess-b0d2c.appspot.com",
messagingSenderId: "862405921020",
appId: "1:862405921020:web:029136c22b33ec84d2af79",
measurementId: "G-ZXZ50M7GRY"
};
firebase.initializeApp(config);
export default firebase;
是的,我确实做了 npm 我安装了 firebase。我现在不知道该怎么做。任何建议都非常感谢。
【问题讨论】:
-
第二个截图规则是针对实时数据库的,不是firestore。它们有不同的语法。
-
@Phix 我正在尝试使用实时数据库
-
屏幕截图中的 url 表示您正在配置 firestore,而不是 rtdb。
标签: javascript reactjs firebase google-cloud-firestore