gpt4 book ai didi

javascript - react 应用程序拒绝了 Firebase 权限

转载 作者:行者123 更新时间:2023-12-04 10:53:14 25 4
gpt4 key购买 nike

我正在尝试将国际象棋游戏保存到 firebase。我有一个 react 应用程序,当我使用 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

我读到我需要更改规则以删除开发身份验证,但这似乎不起作用:

enter image description here

这是相关的代码:
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 i install firebase。我不知道此时该怎么办。任何建议都非常感谢。

最佳答案

好的,所以我只是通过将顶部屏幕截图顶部的按钮更改为“实时数据库”来解决它。就是这样。解决了。

谢谢。

关于javascript - react 应用程序拒绝了 Firebase 权限,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59363581/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com