我已经从redux动作文件创建了对数据库的调用,它总是返回一个空对象。给定一天任务的数据嵌套在JSON中的date对象中,我试图仅访问给定用户发布到Firebase数据库的任务。
我可以授权用户从Firebase提取内容而无需询问特定任务,但是当使用下面的查询参数(请参阅axios调用)时,它会返回:
{}
仅此而已。
redux操作文件中的axios.get调用
export const fetchTasks = (token, userId) => {
return dispatch => {
dispatch( fetchTasksStart(token, userId));
const queryParams = '?auth=' + token + '&orderBy="userId"&equalTo="' + userId + '"';
axios.get('./tasks.json' + queryParams)
.then( response => {
const fetchedTasks = [];
for (let key in response.data) {
fetchedTasks.push( {
...response.data[key],
id: key
} );
}
console.log(response.data);
dispatch(fetchTasksSuccess(fetchedTasks));
} )
.catch(err => {
dispatch(fetchTasksFail(err));
} );
};
};
Firebase数据库上的JSON数据
{
"tasks" : {
"20181025" : {
"-LPelcWwUK2vB2mxqETB" : {
"date" : "20181025",
"end" : "2018-10-25T10:30:30.113Z",
"hours" : 0,
"minutes" : 0,
"name" : "a",
"seconds" : 2,
"start" : "2018-10-25T10:30:28.521Z",
"token" : "placeholder",
"userId" : "placeholder"
}
}
}
}
Firebase规则:
{
"rules": {
"tasks": {
".read": "auth != null",
".write": "auth != null",
".indexOn": ["userId"]
}
}
}