0

誰もが投稿を閲覧できるシンプルなブログのウェブサイトがありますが、管理者だけが編集できます。私はエラーError: Missing or insufficient permissions.ブログのウェブサイトのFirestoreのルール

を取得

{ 
    email:"[email protected]" 
}, 
{ 
    email:"[email protected]" 
} 

マイクラウドFirestoreルール

service cloud.firestore { 
    match /databases/{database}/documents { 
    match /posts/{post} { 
     allow read; 
     allow write: if get(/databases/$(database)/documents/admins/$(admin)).data.email == request.auth.token.email; 
    } 
    } 
} 

を:コレクション文書がどのように見えるの管理者に

{ 
    title:"Hello World", 
    body:"Hello Brian" 
}, 
{ 
    title:"Gumdrops", 
    body:"Goody, goody gumdrops" 
}, 

ポスト収集文書は次のようになり私はAngularFire2を使用していたクライアント側で

は、そのための私のコードはそうなります。私は間違って何をやっている

import { Component } from '@angular/core'; 
import { AuthService } from '../auth/auth.service'; 
import { AngularFirestore, AngularFirestoreCollection } from 'angularfire2/firestore'; 

export interface Post { 
    id?: string; 
    title: string; 
    body: string; 
} 

@Component({ 
    selector: 'app-home', 
    templateUrl: './home.component.html', 
    styleUrls: ['./home.component.css'] 
}) 

export class HomeComponent { 

    private postsCollection: AngularFirestoreCollection<Post>; 
    public posts:any; 

    constructor(
    private afs: AngularFirestore, 
    public authService: AuthService 
) { 
    this.postsCollection = afs.collection<Post>('posts'); 

    this.posts = this.postsCollection.snapshotChanges().map(actions => { 
     return actions.map(a => { 
     const data = a.payload.doc.data() as Post; 
     data.id = a.payload.doc.id; 
     return data; 
     }); 
    }); 
    } 

    addPost(post) { 
    this.postsCollection.add(post).then((ret) => { 
    console.log('post added'); 
    }, (error) => { 
    console.log(error); 
    }); 
} 

+0

質問を編集して、そのエラーを発生させるコードを表示できますか? –

+0

私は読書に問題はなく、私のルールを「書き込み許可」に変更すると、それも機能します。 –

+0

あなたは 'プッシュキー'を管理者のキーとして使用していますか? – Hareesh

答えて

0

I FINALLYは、

ファイアストアルールが間違っていました。代わりにusersというコレクションを作成しました。 idは、ユーザーの電子メールアドレスであり、それはtrue

からadminフィールドが設定されている続いて、次のルールがユーザのみのコレクションに記載されている管理者が変更を加えることができます。

service cloud.firestore { 
    match /databases/{database}/documents { 
    match /{document=**} { 
     allow read; 
     allow write: if get(/databases/$(database)/documents/users/$(request.auth.token.email)).data.admin == true; 
    } 
    } 
} 

yay!

関連する問題