我有一个函数,为任何用户返回用户消息,但当我使用userid为我的查询firebase工作true并返回消息,但当我传递otheruserid不幸不返回用户消息
firebaseGetMessages({ commit, state },otherUserId) {
let userId = state.userDetails.userId
//messagesRef = firebaseDb.ref('userMessages/' + userId ) //ok
messagesRef = firebaseDb.ref('userMessages/' + otherUserId) //not ok
messagesRef.on('child_added', snapshot => {
let messageDetails = snapshot.val()
let messageId = snapshot.key
commit('addMessage', {
messageId,
messageDetails
})
}
)
},
i try with单引号("'")+ otherUserId +"'")和引号('"' + otherUserId +'"')但不生效
这是我的实时数据库结构
userMessages
{
"0FXpksPdL4OAf9KAXx9B0R6nzmh2": {
"-N6giImvaGnHl2L33rA9": {
"content": "test sms",
"fromId": "Yto2rkMyXJNVkWS3xAOJgUjXFzI30",
"isGroup": "true",
"messageId": "-N6giImvaGnHl2L33rA9",
"phone": "+989034015019",
"timestamp": "1657533972119",
"toId": "-N4zbr74Vw5WeYkbnVlb",
"type": "1"
},
"-N6w7t_jTLazBcbLnIau": {
"content": "Test message 1",
"fromId": "Yto2rkMyXJNVkWS3xAOJgUjXFzI3",
"messageId": "-N6w7t_jTLazBcbLnIau",
"phone": "+989034015019",
"timestamp": "1657792676492",
"toId": "0FXpksPdL4OAf9KAXx9B0R6nzmh2",
"type": "1"
},
"-N6w8651yjmhOKRHd5xG": {
"content": "Test massege 2",
"fromId": "Yto2rkMyXJNVkWS3xAOJgUjXFzI3",
"messageId": "-N6w8651yjmhOKRHd5xG",
"phone": "+989034015019",
"timestamp": "1657792676592",
"toId": "0FXpksPdL4OAf9KAXx9B0R6nzmh2",
"type": "1"
}
},
"diZUE8slUzbGvCXcmAMRdImyC7S2": {
"-N6ggkKWpAW9tQSzCKvF": {
"content": "test message group",
"fromId": "Yto2rkMyXJNVkWS3xAOJgUjXFzI3",
"messageId": "-N6ggkKWpAW9tQSzCKvF",
"phone": "+989034015019",
"timestamp": "1657533564699",
"toId": "diZUE8slUzbGvCXcmAMRdImyC7S2",
"type": "1"
}
}
}
我测试了这段代码,但没有成功:
let Other=otherUserId
messagesRef = firebaseDb.ref('userMessages/0FXpksPdL4OAf9KAXx9B0R6nzmh2' )
or
messagesRef = firebaseDb.ref('userMessages/'+ Other)
请注意,用户id存储在带有引号的vuex对象中,例如"0FXpksPdL4OAf9KAXx9B0R6nzmh2"$route
我不明白为什么userid返回数据而otheruserid没有返回数据
我检查之间的交通网络和websocket节重火力点,意识到重火力点返回没有权限阅读其他用户的信息这是在检查部分-网络和WS:
req1-{"t":"d","d":{"r":5,"a":"q","b":{"p":"/userMessages/340SgcUw8xaD2jjNlkpSlRVaqzc2","h":""}}}
response-1-1-{"t":"d","d":{"r":5,"b":{"s":"permission_denied","d":"Permission denied"}}}