firebase / firebase-unity-sdk

The Firebase SDK for Unity
http://firebase.google.com
Apache License 2.0
216 stars 35 forks source link

[Question] Auth not working in Unity editor #1098

Closed zxt385189207 closed 1 week ago

zxt385189207 commented 2 weeks ago

What is your question?

Unable to signin properly in the unity editor environment, but can sginin and upload and download files on my Android phone.

FirebaseException: An internal error has occurred.

I don't know where the setup caused this problem and I can't test the functionality in the unity editor.

Something like that https://github.com/firebase/firebase-cpp-sdk/issues/10 , I wrote a simple demo with no other SDK.

I need help, please.

Firebase.FirebaseApp.LogLevel = Firebase.LogLevel.Verbose;
Added app name=__FIRAPP_DEFAULT: options, api_key=..., app_id=....., database_url=, messaging_sender_id=....., storage_bucket=test-xxxx.appspot.com, project_id=test-xxxx (0x01788e20)
UnityEngine.Debug:Log (object)

Creating Auth ..... for App ....
UnityEngine.Debug:Log (object)

Cloud Storage gs://test-xxxxxx.appspot.com: Created __FIRAPP_DEFAULTgs://test-xxxxx.appspot.com
UnityEngine.Debug:Log (object)

LoadUserData: Credential com.xxxx.xxxx.test-xxxx.firebase.auth/__FIRAPP_DEFAULT[0] not found
UnityEngine.Debug:Log (object)

Failed to read user data for app (__FIRAPP_DEFAULT).  This could happen if the current user doesn't have access to the keystore, the keystore has been corrupted or the app intentionally deleted the stored data.
UnityEngine.Debug:Log (object)

DeleteUserData: Credential com.xxxx.xxxx.test-xxxx.firebase.auth/__FIRAPP_DEFAULT[0] not found
UnityEngine.Debug:Log (object)

Firebase Unity SDK Version

11.6.0 and 12.2.0

Unity editor version

2021.3.12f1

Installation Method

Unity Package Manager

Problematic Firebase Component(s)

Authentication

Other Firebase Component(s) in use

Storage

Additional SDKs you are using

No response

Targeted Platform(s)

Desktop

Unity editor platform

Windows

Scripting Runtime

IL2CPP

Release Distribution Type

Pre-built SDK from https://firebase.google.com/download/unity

google-oss-bot commented 2 weeks ago

I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight.

argzdev commented 2 weeks ago

Thanks for reaching out, @zxt385189207. There was also a similar issue filed before #1048 regarding Auth login. Did you recently change or restrict the API access? This could have triggered the issue.

zxt385189207 commented 2 weeks ago

Thanks for reaching out, @zxt385189207. There was also a similar issue filed before #1048 regarding Auth login. Did you recently change or restrict the API access? This could have triggered the issue.

I did not impose any restrictions, or is it possible that Firebase has default settings?

zxt385189207 commented 2 weeks ago

By the way, on another computer the same project printed USE_AUTH_EMULATOR not set.

zxt385189207 commented 2 weeks ago

https://github.com/firebase/firebase-unity-sdk/tree/main/auth/testapp

  1. No additional code was added.
  2. The Auth package was imported.
  3. The google-services.json file was imported, and google-services-desktop.json was automatically generated.
  4. Clicked unity play.
  5. click SigninAnonymouslyAsync Button

image

  1. quit Unity

QQ_1725199175453

With this code, turning off UNITYEDITOR can wait indefinitely. So What's the problem?

argzdev commented 2 weeks ago

Sorry, I'm not sure what the issue is. I'm unable to reproduce the same behavior on my side. You mentioned that the issue is also reproducible on another computer, I wonder if the issue is the google-services.json. Could you try using a different Firebase project and see if the same behavior is encountered?

Also any chance you can share an MCVE? Please remove any PII (personally identifiable information). This'll help us speed up the investigation. Thanks!

zxt385189207 commented 2 weeks ago

@argzdev

I think it might be a network issue. I created two projects and tried using different google-services.json files, but the result was the same. I'm a Unity developer in China, and I’m affected by the VPN. It seems that most developers don’t debug code or test in the Unity Editor, but rather on an emulator or real device. This issue seems to be quite rare. It's possible that if I send an MCVE, it might work fine in your network environment. I'm currently using the official Auth sample code.

I encountered the following error:

Failed to read user data for app (__FIRAPP_DEFAULT). This could happen if the current user doesn't have access to the keystore, the keystore has been corrupted or the app intentionally deleted the stored data.
UnityEngine.Debug:Log (object)

In what situations does this error occur, and how can the client determine whether the issue is related to the network or the google-services.json ?

argzdev commented 1 week ago

Thanks for the additional information, @zxt385189207. You're right, given that you're using the official Auth sample code, the MCVE will most likely work on our side as well. After further discussing this with our engineers, we came to the conclusion that the issue is due to the network restriction and not related to the google-services.json.

In what situations does this error occur, and how can the client determine whether the issue is related to the network or the google-services.json ?

I thought it could be due to a specific Firebase Project API restriction, which is why I considered changing the google-services.json to another project which might cause a different behavior, but this doesn't seem to be the case. And now, it most certainly is due to a network restriction.

Unfortunately there's not much we can do here, since it looks like everything is working as intended on the SDK side. Network restrictions are out of our control. That said, I'll go ahead and close this thread. If you'd like to know more regarding these restrictions in relation to China, feel free to reach out to our Firebase support for more guidance.

zxt385189207 commented 1 week ago

Can a proxy setting be added to network requests made by the Firebase SDK in Unity? @argzdev

argzdev commented 1 week ago

Sorry, you'll likely need to reach out to our Firebase support for more guidance regarding network connections.