我实际上正在构建一个反应本机和火基群聊天,我需要在适当的渠道中将用户分开。我有6个频道与适当的聊天,我不想事实,一个用户可以创建他的频道。在我的应用程序中,我想授权访问A组中的5个用户,B组中的8个用户,等等。

我的规则是:
{
"rules": {
"GeneralMessage": {
".read": "root.child('user').child(auth.uid).child('inGeneral').child('GeneralMessage').child('read').val() === true",
".write": "root.child('user').child(auth.uid).child('inGeneral').child('GeneralMessage').child('write').val() === true"
}
}
}但这不允许我去读和写选项。
编辑:我在房间里推聊天的反应本机代码。
import * as types from './actionTypes'
import firebaseService from '../../services/firebase'
const FIREBASE_REF_MESSAGES = firebaseService.database().ref('/GeneralMessage')
const FIREBASE_REF_MESSAGES_LIMIT = 20
export const sendMessage = message => {
return (dispatch) => {
dispatch(chatMessageLoading())
let currentUser = firebaseService.auth().currentUser
let createdAt = new Date().getTime()
let chatMessage = {
text: message,
createdAt: createdAt,
user: {
id: currentUser.uid,
email: currentUser.email,
}
}
FIREBASE_REF_MESSAGES.push().set(chatMessage, (error) => {
if (error) {
dispatch(chatMessageError(error.message))
} else {
dispatch(chatMessageSuccess())
}
})
}
}
export const updateMessage = text => {
return (dispatch) => {
dispatch(chatUpdateMessage(text))
}
}
export const loadMessages = () => {
return (dispatch) => {
FIREBASE_REF_MESSAGES.limitToLast(FIREBASE_REF_MESSAGES_LIMIT).on('value', (snapshot) => {
dispatch(loadMessagesSuccess(snapshot.val()))
}, (errorObject) => {
dispatch(loadMessagesError(errorObject.message))
})
}
}
const chatMessageLoading = () => ({
type: types.CHAT_MESSAGE_LOADING
})
const chatMessageSuccess = () => ({
type: types.CHAT_MESSAGE_SUCCESS
})
const chatMessageError = error => ({
type: types.CHAT_MESSAGE_ERROR,
error
})
const chatUpdateMessage = text => ({
type: types.CHAT_MESSAGE_UPDATE,
text
})
const loadMessagesSuccess = messages => ({
type: types.CHAT_LOAD_MESSAGES_SUCCESS,
messages
})
const loadMessagesError = error => ({
type: types.CHAT_LOAD_MESSAGES_ERROR,
error
})发布于 2018-07-12 09:49:14
您的数据结构和安全规则并不完全匹配。您有一个关于/user/user.uid/inGeneral/GeneralMessage/read的规则,但是在您的数据结构中inGeneral下没有一个GeneralMessage子级。
使用当前的数据存储,您的规则必须如下所示:
{
"rules": {
"GeneralMessage": {
".read": "root.child('user').child(auth.uid).child('inGeneral').child('general').val() === true",
".write": "root.child('user').child(auth.uid).child('inGeneral').child('general').val() === true"
}
}
}https://stackoverflow.com/questions/51301583
复制相似问题