When a user wants to get his data he need to be authenticated. But when he retrieves data firestore doesn't let to get the data. I add a lot of debugs and in Unity the user is always authenticated and I get this Exception.
Firebase initializes correctly and here is the code to get the user data
Debug.Log(FirebaseAuth.DefaultInstance.CurrentUser.UserID);
FDb.Collection("SavedGames").Document("SavedGames").Collection(FirebaseAuth.DefaultInstance.CurrentUser.UserId).GetSnapshotAsync().ContinueWith(task => {
if (task.IsCompleted)
{
Debug.Log(task.Exception);
}
});
And here are the Firestor rules
match /SavedGames/{documents=**} {
allow read, write: if isAuth();
}
function isAuth(){
return request.auth != null;
}
The Debug:
SPufxax5oJQXACF9wqRbBeBX1KG2
System.AggregateException: One or more errors occurred. ---> Firebase.Firestore.FirestoreException: Missing or insufficient permissions.
at Firebase.Firestore.Internal.Util.FlattenAndThrowException (System.Threading.Tasks.Task completedTask) [0x0003d] in Z:\tmp\tmp.DnKB31Zq3X\firebase\firestore\client\unity\proxy\Util.cs:97
at Firebase.Firestore.Internal.Util+<MapResult>c__AnonStorey0`2[T,U].<>m__0 (System.Threading.Tasks.Task`1[TResult] completedTask) [0x00000] in Z:\tmp\tmp.DnKB31Zq3X\firebase\firestore\client\unity\proxy\Util.cs:59
at System.Threading.Tasks.ContinuationResultTaskFromResultTask`2[TAntecedentResult,TResult].InnerInvoke () [0x00024] in <695d1cc93cca45069c528c15c9fdd749>:0
at System.Threading.Tasks.Task.Execute () [0x00010] in <695d1cc93cca45069c528c15c9fdd749>:0
--- End of inner exception stack trace ---
---> (Inner Exception #0) Firebase.Firestore.FirestoreException: Missing or insufficient permissions.
at Firebase.Firestore.Internal.Util.FlattenAndThrowException (System.Threading.Tasks.Task completedTask) [0x0003d] in Z:\tmp\tmp.DnKB31Zq3X\firebase\firestore\client\unity\proxy\Util.cs:97
at Firebase.Firestore.Internal.Util+<MapResult>c__AnonStorey0`2[T,U].<>m__0 (System.Threading.Tasks.Task`1[TResult] completedTask) [0x00000] in Z:\tmp\tmp.DnKB31Zq3X\firebase\firestore\client\unity\proxy\Util.cs:59
at System.Threading.Tasks.ContinuationResultTaskFromResultTask`2[TAntecedentResult,TResult].InnerInvoke () [0x00024] in <695d1cc93cca45069c528c15c9fdd749>:0
at System.Threading.Tasks.Task.Execute () [0x00010] in <695d1cc93cca45069c528c15c9fdd749>:0 <---
UnityEngine.Debug:Log (object)
FirebaseFirestoreManager/<>c:<ReadData>b__17_1 (System.Threading.Tasks.Task`1<Firebase.Firestore.QuerySnapshot>) (at Assets/Scripts/MirariaId/FirebaseFirestoreManager.cs:116)
System.Threading._ThreadPoolWaitCallback:PerformWaitCallback ()
at System.Threading.Tasks.Task.Execute () [0x00010] in <695d1cc93cca45069c528c15c9fdd749>:0 <---
UnityEngine.Debug:Log (object)
FirebaseFirestoreManager/<>c:<ReadData>b__17_1 (System.Threading.Tasks.Task`1<Firebase.Firestore.QuerySnapshot>) (at Assets/Scripts/MirariaId/FirebaseFirestoreManager.cs:116)
System.Threading._ThreadPoolWaitCallback:PerformWaitCallback ()
I can write data but i can't retrieve it.
Also I have tried to put the rules to true instead isAuth() and it works.
I have tried with firebase sdk 7.1.0, 7.2.0, 8.0.0 and 8.1.0 and I use Unity 2020.3.14f1(LTS).
I'm back,
I downgraded the sdk to 7.0.2 and now it works fine!
I don't know why but it is correct.