这是一个奇怪的!我有几个开发人员使用Firebase和React Native构建移动应用程序。他们让一切正常,并在1月底离开了公司。我已经把它拿到了我们的员工手中。但是我遇到了问题! 在他们离开之前,他们将我添加到Firebase帐户,然后我在那里创建了一个iOS应用程序,并确保我已将React Native代码更改为指向新的Firebase iOS应用程序。 这似乎很好,因为用户可以使用Facebook登录,他们的凭据被添加到身份验证表中,并且他们被赋予UID。然后,在我们的数据库中将该UID用作主键,并且似乎添加得很好,但是在下一次读/写尝试时,我们会收到权限被拒绝错误:
Error onDBEvent: Error Domain=com.firebase Code=1 "Permission Denied" UserInfo={NSLocalizedDescription=Permission Denied}
由于这是我没有写过的代码,我在黑暗中刺伤了问题的位置,我认为这是在这个函数中:
export function likeDestination (destinationKey, score, taggedImageSetIndex, imageTagIndex) {
return function (dispatch, getState) {
const user = getState().auth.auth
let iTagIndex = imageTagIndex + 1
let updateValue = {}
updateValue[destinationKey] = score
console.log('likeDestination:: userID=', user.uid);
console.log('likeDestination:: taggedImageSetIndex=', taggedImageSetIndex);
// Set the user's preference for this tag then update (increment) the imageTagIndex
return firestack.database.ref(`user-data/${user.uid}/tagSets/${taggedImageSetIndex}/userScores`)
.update(updateValue)
.then(() => {
return firestack.database.ref(`user-data/${user.uid}/tagSets/${taggedImageSetIndex}`).update({imageTagIndex: iTagIndex})
})
.catch(err => {
console.log('Error in setting destination "like" data to Firebase:', err)
RouterActions.ErrorPage({ error: err })
})
}
}
值得一提的是,上面的console.log
语句会返回正确的值。
我可以在下面找到getState函数的唯一引用,不确定.auth.auth
调用将从数据库中获取用户的操作,但它似乎有效!
export function getState (toggle) {
return {
type: GET_STATE,
payload: toggle
}
}
我已经查看了类似问题的各种帖子,他们似乎都指向Firebase中的规则。规则没有改变,因为它工作,如果我通过模拟器运行这些查询,我会在相关的读写规则旁边找到一个大的勾号。以下是DB的规则:
{
"rules": {
"destination-scores": {
".read": true,
".write": false
},
"destinations": {
".read": true,
".write": false
},
"tv-admins": {
".read": "auth != null",
".write": false
},
"tv-queues": {
".read": "auth != null",
".write": "auth != null"
},
"tv-screens": {
".read": "auth != null",
".write": "root.child('tv-admins').child('ids').val().contains(auth.uid)",
".indexOn": "status"
},
"user-data": {
"$uid": {
".read": "$uid === auth.uid",
".write": "$uid === auth.uid"
}
}
}
}
上面代码示例中的查询定位于user-data
规则,并且在模拟器中工作正常,而不是来自应用。正如我所提到的,规则没有改变。更改的是代码现在在我的机器上运行,而不是原始开发人员,并且在Firebase中创建了一个新的iOS应用程序。
正如我还提到的,我确保已使用新的详细信息替换旧的Firebase API密钥,邮件发件人ID,Auth域,DB URL和存储桶。我相信这是有效的,因为用户可以通过Facebook登录并进入应用程序的第一阶段......此时他们的用户数据已添加到user-data
表中。
我是Firebase和React Native的新手,所以我不完全确定在代码中发生了什么,但我怀疑它可能是这个功能:
export function connectUserData (firedb, user, authProvider, onUserDataChanged) {
const now = new Date()
return firedb.ref(`user-data/${user.uid}`)
.update({ email: user.email, connectedAt: now.toISOString(), authProvider: authProvider })
.catch(err => {
console.log('Error in updating meta data in connectUserData():', err)
throw new Error('Error in updating meta data in connectUserData()!')
})
}
这是作为init函数的一部分调用的,用于检查用户是否经过身份验证...如同,它们存在于Firebase中的身份验证表/列表中
我只是不明白为什么我在获得许可后会被拒绝,从字面上看,几秒钟之前!任何帮助将不胜感激