How to properly await for errors from AuthenticationService.Instance.SignInWithUnityAsync

Hi , I am currenty trying to implement Unity Authentication into my mobile game. Everything works fine for now , but the question is how to properly catch authentication errors. So my case is, when I call sign in, browser with unity login page appears, but when I force close it without entering any credentials, none of my try catches working. So basically I dont know if sign in worked or not, and since I am disabling sign in button on trigger, I cant enable sign in button back.

Here is my code :

private async void _SignInWithUnity()
        {
            //Remove last signed user data
            _loggedUser.OnNext(null);

            try
            {
                await AuthenticationService.Instance.SignInWithUnityAsync(PlayerAccountService.Instance.AccessToken);
                Debug.Log("Signed in with Unity");

                var pi = AuthenticationService.Instance.PlayerInfo;


                _loggedUser.OnNext(pi);
            }
            catch (AuthenticationException ex)
            {
                Debug.Log("AuthenticationException");
                Debug.LogException(ex);
            }
            catch (RequestFailedException ex)
            {
                Debug.Log("RequestFailedException");
                Debug.LogException(ex);
            }
        }

“force close” means you actually end the application.

If you did the same on desktop, eg use Task Manager to “end process” you wouldn’t get any exceptions either and the next time the app launches, it launches from the start.

I can imagine that you save the app state, perhaps in EditorPrefs, and the next time the app launches it is thinking that you’re waiting for the sign in to succeed or fail while there is actually no sign in procedure going on.

On mobile you can and may have to subscribe to one of the “shutdown” events to perform any last second cleanup.

Hi, thank you for your response. By force close, I meant closing the browser window, not the running mobile game. For example, after clicking the sign-in button, the user decided not to enter credentials and continued in the app without authorization, but since I do not have that error callback from authorization, I can’t re-enable the sign-in button.