我设置了我的 firebase 身份验证,它运行良好。但是,当我加载不同的场景并返回欢迎场景后,身份验证失败。场景切换时,如何重新授权或保持登录状态?
我的授权欢迎场景代码:
public void Start()
{
InitializeFirebase();
InitializePlayGamesPlatform();
SignInPlayGames();
}
public void InitializeFirebase()
{
Debug.Log("UserManager: Setting up Firebase Auth");
auth = Firebase.Auth.FirebaseAuth.DefaultInstance;
auth.StateChanged += AuthStateChanged;
auth.IdTokenChanged += IdTokenChanged;
// Specify valid options to construct a secondary authentication object.
if (otherAuthOptions != null &&
!(String.IsNullOrEmpty(otherAuthOptions.ApiKey) ||
String.IsNullOrEmpty(otherAuthOptions.AppId) ||
String.IsNullOrEmpty(otherAuthOptions.ProjectId)))
{
try
{
otherAuth = Firebase.Auth.FirebaseAuth.GetAuth(Firebase.FirebaseApp.Create(
otherAuthOptions, "Secondary"));
otherAuth.StateChanged += AuthStateChanged;
otherAuth.IdTokenChanged += IdTokenChanged;
}
catch (Exception)
{
Debug.Log("UserManager: ERROR: Failed to initialize secondary authentication object.");
}
}
AuthStateChanged(this, null);
}
public void InitializePlayGamesPlatform()
{
PlayGamesClientConfiguration config = new PlayGamesClientConfiguration.Builder()
.RequestServerAuthCode(false)
.Build();
PlayGamesPlatform.InitializeInstance(config);
PlayGamesPlatform.Activate();
auth = FirebaseAuth.DefaultInstance;
}
慕容森
浮云间
相关分类