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

firebase disconnects user when changing scene #326

Closed
H4rdG4m3 opened this issue Mar 6, 2019 · 6 comments
Closed

firebase disconnects user when changing scene #326

H4rdG4m3 opened this issue Mar 6, 2019 · 6 comments

Comments

@H4rdG4m3
Copy link

H4rdG4m3 commented Mar 6, 2019

Please fill in the following fields:

Unity editor version: 2018.3.7
Firebase Unity SDK version: 5.4.4
Additional SDKs you are using (Facebook, AdMob, etc.): email
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:

(Please list the full steps to reproduce the issue. Include device logs, Unity logs, and stack traces if available.)

Please answer the following, if applicable:

Have you been able to reproduce this issue with just the Firebase Unity quickstarts (this GitHub project)?

For some reason when I log in through the Firebase auth, I go to the next scene, however, after that scene I go to another, my user is disconnected, does anyone know the reason?

@H4rdG4m3 H4rdG4m3 added the new New issue. label Mar 6, 2019
@alexames
Copy link

alexames commented Mar 6, 2019

This might be an issue with Unity cleaning up Firebase data between scenes. If you're holding onto the FirebaseApp object in a monobehavior and that object gets cleaned up, the FirebaseApp (and Auth) might get cleaned up with it, causing the user to get logged out. Try holding a global reference to the FirebaseApp object that will persist between scene transitions and see if that fixes the issue.

@alexames
Copy link

alexames commented Mar 6, 2019

Actually, thinking about it more, you should only need to hold on to a reference to Auth, not App, so you can try making the Auth object global instead (or do both, it won't hurt)

@H4rdG4m3
Copy link
Author

H4rdG4m3 commented Mar 7, 2019

I found it interesting, when I tested in the cellar, there was not this error of disconnecting, how can I make to remain always active the global firebase by the unity? could you show me an example?

@Russel1
Copy link

Russel1 commented Mar 18, 2019

Thanks @alexames it works great with reference to Auth and FirebaseApp.

public static Firebase.Auth.FirebaseAuth Auth;
public static FirebaseApp App;
public static DatabaseReference DBReference;
public static FirebaseStorage Storage;

@chkuang-g
Copy link
Contributor

chkuang-g commented Apr 2, 2019

Hi @H4rdG4m3
The simple way to make FirebaseAuth alive across the scene is as @Russel1 mentioned: using a static reference. Or you can make the Unity Object alive using DontDestroyOnLoad flag. Or you can use Singleton pattern.

Please let us know if this resolves your issue.

If the issue remains, it would be very helpful if you can provide "error of disconnecting".

@chkuang-g chkuang-g added type: question and removed new New issue. labels Apr 2, 2019
@patm1987
Copy link

patm1987 commented Apr 22, 2019

Hi @H4rdG4m3 ,

I'd like to chime in here with one more pattern, storing the reference in a ScriptableObject. This will also persist between scenes, you can reference them in serialized fields, and can cut back on the some of the code smell of a static field singleton (although it's effectively the same as one).

If the suggestions here don't resolve your issue, please feel free to re-open this bug!

--Patrick

[Edit: for code samples, this is the talk that caused me to adapt this pattern. I don't follow its recommendations exactly, but it's a great starting point https://www.youtube.com/watch?v=raQ3iHhE_Kk ]

@firebase firebase locked and limited conversation to collaborators Oct 24, 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

5 participants