1

私はfirebaseの初心者です。Firebaseの許可が拒否されました

このルールはどうやって解決されますか?

service cloud.firestore { 
    match /databases/{database}/documents { 
    match /{document=**} { 
     allow read, write: if false; 
    } 
    } 
} 

私は

{ 
    "rules": 
    { 
    ".read": true, 
    ".write": true, 
    } 
} 

、以下にルールを変更しようとしたが、以下

mismatched input '{' expecting {'function', 'service', 'syntax'} 

の誤差がありますが、DB構造です。

db structure

現在、これは(パーミッション拒否を返す保つ)私のコードです:

// [START initialize_database_ref] 
    mDatabase = FirebaseDatabase.getInstance().reference 
    // [END initialize_database_ref] 

    val result = HashMap<String, Any>() 
    result.put("timestamp", getCurrentTime()) 
    result.put("user_id", USER_ID) 
    result.put("x_position", -1) 
    result.put("y_position", -1) 

    mDatabase!!.ref.child("raw data").child("Z9QD79lDzP7MpD6feWeJ").setValue(result).addOnFailureListener(object : OnFailureListener { 
     override fun onFailure(@NonNull e: Exception) { 
      Log.d("firebase", e.localizedMessage) 
     } 
    }) 

任意の助けいただければ幸いです!ありがとう:)

答えて

1

Cloud FirestoreからRealtime Databaseに切り替えてルールを変更することで、この問題を解決できました。 (私はこれを変更した後は、それ以上のエラー上映がなかった!)この問題に苦しんで他の人のために enter image description here

1

は、適切な解決策はfalseしばらくtrue

service cloud.firestore { 
    match /databases/{database}/documents { 
     match /{document=**} { 
      allow read, write: if false; 
     } 
    } 
} 

でテストを変更することです。 プロジェクトに参加する際にセキュリティを追加することを忘れないでください!

+0

私はまたことを試みたが、まだ許可拒否を持っています。私は別の方法で問題を解決したにもかかわらず、私はなぜこれの理由がわからない:( – user3415167

0

「リアルタイムデータベース」または「Cloud Firestore」を使用している場合は、Angular NgModuleとコンポーネントをチェックインする必要があります。 "angularfire2" を使用してdiferencesを参照してください:

REALTIMEデータベース

@NgModule({ 
... 
imports: [ 
    AngularFireDatabaseModule, 
    ... 
], 
providers: [ 
AngularFireDatabase, 
... 
] 
}) 


@Component({...}) 
export class FirestoreComponent{ 
    constructor(private realtimeDb:AngularFireDatabase, ...) { 
     this.locations = realtimeDb.list('locations').valueChanges(); 
    } 
... 
} 

CLOUD FIRESTORE

@NgModule({ 
    ... 
    imports: [ 
     AngularFirestoreModule, 
     ... 
    ] 
}) 

@Component({...}) 
export class FirestoreComponent{ 
    constructor(private firestore:AngularFirestore, ...) { 
     this.locations = firestore.collection('locations').valueChanges(); 
    } 
... 
} 
関連する問題