我试图限制只允许用户读取他发布到 firebase 的数据。身份验证已到位。发布,读取和删除数据只是
但是还没有为 firebase 数据库设置任何真正的规则。
我试图改变这个:
{
"rules": {
"users": {
"$uid": {
".read": "auth != null && auth.uid == $uid"
}
}
}
}
这给了我一个 401 错误(未经授权)。现在我不确定问题可能是什么。我是否可能需要将 uid 显式添加到数据发送中?所以firebase可以尝试匹配来自post和auth.uid的uid。
但我觉得这不能充分保护数据。
编辑:我正在使用的一些代码:
数据服务.ts
storeNotes() {
const notes = this.noteService.getNotes();
this.http
.put(
'https://XXXXXXX.firebaseio.com/notes.json',
notes
)
.subscribe(response => {
console.log(response);
});
}
note.service.ts
private notes: Note[] = [];
getNotes() {
return this.notes.slice();
}
note.model.ts
export class Note {
public userName: string;
public name: string;
public description: string;
constructor(userName: string, name: string, desc: string) {
this.userName = userName;
this.name = name;
this.description = desc;
}
}
我现在还没有发布身份验证数据,因为我不认为它们在这里应该是相关的。还是我错了?