firebaseを用いて、webサイトを動かそうとしていたのですが、
ルールを設定する段階で、問題が発生し、色々な機能が動かなくなってしまいました。
サイトはこちら。
ルールの設定はこんな感じです。
json
1{ 2 3 "rules": { 4 5 ".read": true, 6 7 "users": { 8 ".read": true, 9 10 "$uid": { 11 ".validate": "newData.hasChildren(['explain','profile_image','title','uid','user','userStar'])", 12 13 "user":{ 14 ".write": "$uid === auth.uid", 15 ".validate": "newData.isString() && newData.val().length <= 15", 16 }, 17 "uid":{ 18 ".write": "$uid === auth.uid", 19 ".validate": "newData.isString() && newData.val() == auth.uid", 20 }, 21 "explain":{ 22 ".write": "$uid === auth.uid", 23 ".validate": "newData.isString() && newData.val().length <= 300", 24 }, 25 "title":{ 26 ".write": "$uid === auth.uid", 27 ".validate": "newData.isString() && newData.val().length <= 20", 28 }, 29 "profile_image":{ 30 ".write": "$uid === auth.uid", 31 ".validate": "newData.isString() && newData.val().matches(/^(ht|f)tp(s?):\/\/[0-9a-zA-Z]([-.\w]*[0-9a-zA-Z])*((0-9)*)*(\/?)([a-zA-Z0-9\-\.\?\,\'\/\\+&=%\$#_]*)?$/)" 32 }, 33 "user_posts":{ 34 "$postsId":{ 35 ".write": "$uid === auth.uid", 36 ".validate":"newData.val() === true" 37 } 38 }, 39 "starred_users":{ 40 "$starredUid":{ 41 ".write": "$uid === auth.uid", 42 ".validate":"newData.val() === true", 43 }, 44 }, 45 "userStar":{ 46 ".validate":"newData.hasChild('starCount')", 47 "stars":{ 48 "$starUid":{ 49 ".write":"auth.uid == $starUid && 50 (!data.exists() && newData.exists() && 51 newData.parent().parent().child('starCount').val() == data.parent().parent().child('starCount').val() + 1 52 ) || 53 (data.exists() && !newData.exists() && 54 newData.parent().parent().child('starCount').val() == data.parent().parent().child('starCount').val() - 1 55 )", 56 ".validate": "newData.val() == true" 57 } 58 59 }, 60 "starCount":{ 61 ".write":"auth != null", 62 ".validate":"(newData.val() == data.val() + 1 && 63 newData.parent().child('stars').child(auth.uid).val() == true && 64 !data.parent().child('stars').child(auth.uid).exists() 65 ) || 66 (newData.val() == data.val() - 1 && 67 !newData.parent().child('stars').child(auth.uid).exists() && 68 data.parent().child('stars').child(auth.uid).val() == true 69 )" 70 }, 71 "$others":{ 72 ".validate":false 73 } 74 } 75 76 } 77 }, 78 79 "posts":{ 80 ".read": true, 81 ".write":"auth != null", 82 "$post":{ 83 ".write": "data.exists() ? (newData.child('uid').val() === auth.uid && 84 newData.child('uid').val() === data.child('uid').val()) : 85 newData.child('uid').val() === auth.uid", 86 ".validate":"(newData.hasChildren(['author','body','postComment','postId','postStar','title','uid','timestamp']))|| 87 (newData.hasChildren(['author','body','postComment','postId','postStar','title','uid','timestamp','post_image']))", 88 89 90 "author":{ 91 ".write":"newData.parent().child('uid').val() === auth.uid", 92 ".validate": "newData.isString() && newData.val().length <= 15", 93 }, 94 "title":{ 95 ".write":"newData.parent().child('uid').val() === auth.uid", 96 ".validate": "newData.isString() && newData.val().length <= 20", 97 }, 98 "body":{ 99 ".write":"newData.parent().child('uid').val() === auth.uid", 100 ".validate": "newData.isString() && newData.val().length <= 300", 101 }, 102 "uid":{ 103 ".write":"newData.val() === auth.uid", 104 }, 105 "timestamp":{ 106 ".write":"newData.parent().child('uid').val() === auth.uid", 107 }, 108 "postComment":{ 109 ".validate": "newData.hasChild('commentCount')", 110 ".write":true, 111 "commentCount":{ 112 ".write":"auth != null", 113 ".validate":"(newData.val() == data.val() + 1) ||(newData.val() == data.val() - 1)" 114 }, 115 "comments":{ 116 "$commentId":{ 117 ".write":"auth != null && 118 ((!data.exists() && newData.exists() && newData.child('uid').val() === auth.uid && 119 newData.parent().parent().child('commentCount').val() == data.parent().parent().child('commentCount').val() + 1 120 ) || 121 (data.exists() && !newData.exists() && 122 newData.parent().parent().child('commentCount').val() == data.parent().parent().child('commentCount').val() - 1 123 ))", 124 ".validate": "newData.val() == true" 125 } 126 }, 127 "$others": { 128 ".write": false 129 } 130 }, 131 "postId":{ 132 ".write": "$post === newData.val()", 133 }, 134 "postStar":{ 135 ".write": "newData.val() === data.val() + 1", 136 }, 137 }, 138 }, 139 140 "comments":{ 141 ".read": true, 142 ".write":true, 143 144 "$comment":{ 145 ".write": "newData.child('uid').val() === auth.uid", 146 ".validate": "newData.hasChildren(['author','body','commentId','uid','profile_image'])", 147 148 } 149 }, 150 151 152 "$others": { 153 ".validate": false 154 } 155 156 157 } 158 159 160}
サイトを見てもらうとどのようなサイトかわかると思うのですが、軽いSNSサイトのようなものです。投稿したりフォローしたりコメントしたり。
現在このルールのpostsのどこかのルールを通過できず投稿ができません。また、commentもpost内のcommentsにコメントIDを付加できず怪しい状態です。
ルールの設定に詳しい方、もしくは解決できそうな方、回答お願いします。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/11/16 15:49
2017/11/17 05:52
2017/11/17 09:57