Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Database Permission Issue - was working now isnt #464

Closed
acoale opened this issue Sep 9, 2019 · 5 comments
Closed

Database Permission Issue - was working now isnt #464

acoale opened this issue Sep 9, 2019 · 5 comments

Comments

@acoale
Copy link

acoale commented Sep 9, 2019

Please fill in the following fields:

Unity editor version: 2018.4.8f1
Firebase Unity SDK version: 5.4.4
Firebase plugins in use (Auth, Database, etc.): Auth, database, storage, analytics
Additional SDKs you are using (Facebook, AdMob, etc.): Mapbox
Platform you are using the Unity editor on (Mac, Windows, or Linux): Windows
Platform you are targeting (iOS, Android, and/or desktop): Android

Please describe the issue here:

System.AggregateException: One or more errors occurred. ---> Firebase.Database.DatabaseException: Firebase Database error: Permission denied
--- End of inner exception stack trace ---
---> (Inner Exception #0) Firebase.Database.DatabaseException: Firebase Database error: Permission denied<---

UnityEngine.Debug:Log(Object)
LoginPanel:b__34_0(Task`1) (at Assets/Scripts/Panels/LoginPanel.cs:130)
System.Threading._ThreadPoolWaitCallback:PerformWaitCallback()

Please answer the following, if applicable:

N/A

The issue is that I changed from .net35 to .net4x I updated the firebase plugin to reflect the appropriate .net version. I use auth to sign in first then access the database. Its textbook and pulled almost completely from docs. I do get a user signed in successfully log from AUTH.

PERMISSIONS:
{
"rules": {
".read": "auth != null",
".write": "auth != null"
}
}

Where the permission is denied:

private void GetUserProfile()
    {
        auth = FirebaseAuth.DefaultInstance;
        auth.SignInWithEmailAndPasswordAsync(email.text, password.text).ContinueWith(task =>
        {
            if (task.IsCanceled)
            {
                Debug.LogError("SignInWithEmailAndPasswordAsync was canceled.");
                ErrorMessage.Instance.ErrorHandler("Error: Sign in was canceled.");
                //Error.ErrorHandler("Sign In Canceled.");
                return;
            }
            if (task.IsFaulted)
            {
                Debug.LogError("Sign In With Email And PasswordAsync encountered an error: "   task.Exception);
                ErrorMessage.Instance.ErrorHandler("Error: Email and/or Password do not match.");
                Debug.Log("Test");
                return;
            }
            FirebaseUser newUser = task.Result;
            Debug.LogFormat("User signed in successfully: {0} ({1})",
                "User Display Name: "   newUser.DisplayName, "User ID: "   newUser.UserId);
            userID = newUser.UserId;
            Debug.Log(userID);
            PullDatabase();
            email.text = "";
            password.text = "";
        });
    }

private void PullDatabase()
    {
        Debug.Log("Pulling Database:...");
        FirebaseDatabase.DefaultInstance.GetReference("Users").Child(userID)
        .GetValueAsync().ContinueWith(task =>
        {
            if (task.IsFaulted)
            {
                Debug.Log("Could Not Sign in "   userID);
                Debug.Log(task.Exception);
            }
            else if (task.IsCompleted)
            {
                DataSnapshot snapshot = task.Result;                
            }
        });
    }
@acoale acoale added the new New issue. label Sep 9, 2019
@muflub
Copy link

muflub commented Sep 12, 2019

Did you solve this with your comment in #466 @acoale ?

@acoale
Copy link
Author

acoale commented Sep 12, 2019

No, the upgrade I think is what caused this issue. I am really not sure why I all of a sudden am getting a permission denied error. I was actually about to rebuild the entire thing as I have checked to make sure the most updated google-services.json file was updated, the rules look fine, the code was, as stated, pretty textbook. Any insight would be helpful.

@acoale
Copy link
Author

acoale commented Sep 13, 2019

So an update to this. I created a new project in firebase to test permissions and linked the current project to that instead. Long story short, I have two methods that deal with registering users and/or pulling user details from the database. I was able to register a user and write their information to the database. BUT once I restarted the app and tried to pull the database (by logging in) I get the permission denied error.

UPDATE: I set rules that just allowed .read and .write to true. This enables me to proceed with my app however, it seems that Firebase Database isn't seeing the auth variable after authentication is achieved.

UPDATE: I resolved this issue, it made no sense but I had to establish the auth in a different location.

@alexames
Copy link

Hi acoale,

Is there a reason you're using 5.4.4 instead of a newer release of the SDK? According to our release notes there have been a handful of bugfixes to authenticating in database. It's likely the issue you're seeing could be solved by just upgrading to the newest release. Nothing you've posted here immediately jumps out as being obviously wrong, so you might just be running into a bug in the version of the SDK you're using.

@acoale
Copy link
Author

acoale commented Sep 18, 2019

When I was trying to update I got the .dll error. I was updating to 6.4, I am currently on 6.5 as that version seemed to have fixed that issue, I am running on 2018.4.8f1 but only running .Net 3.x as I have an issue where Unity is not running code that is working on 3.x and I am trying to track down the reason why.

@acoale acoale closed this as completed Sep 18, 2019
@stewartmiles stewartmiles added type: question and removed new New issue. labels Sep 18, 2019
@firebase firebase locked and limited conversation to collaborators Oct 23, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants