Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/firebase/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Firebase 使用Kotlin&;MVVM_Firebase_Kotlin_Mvvm_Google Cloud Firestore_Android Livedata - Fatal编程技术网

Firebase 使用Kotlin&;MVVM

Firebase 使用Kotlin&;MVVM,firebase,kotlin,mvvm,google-cloud-firestore,android-livedata,Firebase,Kotlin,Mvvm,Google Cloud Firestore,Android Livedata,我对使用Kotlin使用MVVP架构设置我的应用程序感到相当困惑 具体来说,我正在尝试使用此结构设置Firebase Auth 我一直在关注这篇优秀的Java文章: 因此,我设置了一个简单的启动屏幕,在这个屏幕后面,我创建了: SplashRepository-连接到Firestore数据库 SplashViewModel-观察存储库 SplashActivity-观察ViewModel 代码如下: 类存储库{ private val firebaseAuth=firebaseAuth.get

我对使用Kotlin使用MVVP架构设置我的应用程序感到相当困惑

具体来说,我正在尝试使用此结构设置Firebase Auth

我一直在关注这篇优秀的Java文章:

因此,我设置了一个简单的启动屏幕,在这个屏幕后面,我创建了:

SplashRepository-连接到Firestore数据库

SplashViewModel-观察存储库

SplashActivity-观察ViewModel

代码如下:

类存储库{
private val firebaseAuth=firebaseAuth.getInstance()
private val firestore=FirebaseFirestore.getInstance()
private val userscolectionref=firestore.collection(“用户”)
private val user:UserObject=UserObject()
趣味checkIfUserIsAuthenticatedInFirebase():MutableLiveData{
val isUserAuthenticateinfibreAssembleLiveData=MutableLiveData()
val firebaseUser=firebaseAuth.currentUser
if(firebaseUser==null){
user.isAuthenticated=false
IsUserAuthenticateInfireAssembleLiveData.setValue(用户)
}否则{
user.userID=firebaseUser.uid
user.isAuthenticated=true
IsUserAuthenticateInfireAssembleLiveData.setValue(用户)
}
返回isUserAuthenticateinfibreAssembleLiveData
}
fun addUserToLiveData(userID:String):MutableLiveData{
val userMutableLiveData:MutableLiveData=MutableLiveData()
usersCollectionRef.document(userID.get())
.addOnCompleteListener(OnCompleteListener{userTask:Task->
如果(userTask.isSuccessful){
val document=userTask.result
如果(文档!!.exists()){
val user:UserObject?=document.toObject(UserObject::class.java)
userMutableLiveData.setValue(用户)
}
}否则{
Log.d(标记,userTask.exception!!.message)
}
})
返回userMutableLiveData
}

}
你好,斯坎帕雷利。我写了那篇文章,就我所见,你的Kotlin代码对我来说很好。所以你说不管用户是否经过身份验证,你都不会被重定向到任何地方?你确定你有正确的权限吗?嗨,Alex,谢谢你的回复。我已经在数据库上设置了当前规则集://Allow read/write access on all documents to any user signed to the application service cloud.firestore{match/databases/{database}/documents{match/{document=**}{Allow read,write:if request.auth.uid!=null;}}}},我应该注意,我没有使用资源就设置了启动屏幕。。(我并不认为这是问题所在)。是我的波乔吗?你也有同样的行为?在if-else语句的每个部分中添加一个log语句,会触发哪一个?它似乎没有到达那里。我将不得不花一些时间稍后调试-至少我在正确的轨道上谢谢!将更新时,我发现!我的帖子被审核了(希望这个评论可以!),但为了完整起见,我在这里用解决方案更新了我的问题: