0
votes

I'm using https://www.pujolsluis.com/google-client-plugin-for-xamarin/ for google sign in xamarin forms. Both Login and Logout methods work fine; but i have to hide the login page after successful login.After opening the app from second time onwards, logout method throws java.Lang.IlegalStateException<Timeout exceeded getting exception details> ,cannot logout.Active token is null.How to handle this exception? How to logout successfully from second time?

Login:

public IGoogleClientManager googleClientManager;
googleClientManager = CrossGoogleClient.Current;

    private void google_btn_Clicked(object sender, EventArgs e)
    {
        if (CrossConnectivity.Current.IsConnected)
        {
            googleClientManager.LoginAsync();
            googleClientManager.OnLogin += OnLoginCompleted;
            //   CrossGoogleClient.Current.SilentLoginAsync();
            //   var userToken = CrossGoogleClient.Current.ActiveToken;
        }
        else
        {
            DependencyService.Get<IToast>().LongAlert("Check  Connection!");
        }
    }

    public async void OnLoginCompleted(object s,
    GoogleClientResultEventArgs<GoogleUser> loginEventArgs)
    {           
        if (loginEventArgs.Data != null)
        {
            GoogleUser googleUser = loginEventArgs.Data;                 
            string google_name = googleUser.Name;               
            string google_mail = googleUser.Email;        
             Uri google_img = googleUser.Picture;                
            googleClientManager.OnLogin -= OnLoginCompleted;                                    
        }                                       
    }

Logout:

    public void Logout()
    {
        googleClientManager.OnLogout += OnLogoutCompleted;
        googleClientManager.Logout(); // throws exception from secondtime after hiding loginpage
    }

    private void OnLogoutCompleted(object sender, EventArgs loginEventArgs)
    {
        googleClientManager.OnLogout -= OnLogoutCompleted;
    }
1
Are you updating the token on every launch or not?FreakyAli
active token is nullVipin Krishna
That is your problem why is it null it should have a value right?FreakyAli
@G.hakim getting user details,login also ok,but active token null.Vipin Krishna
So this works as expected the first time?FreakyAli

1 Answers

1
votes

You are getting this exception because you are trying to log out of a google client that is no longer connected as the message of the exception states.

Google Client Illegal State Exception Screenshot

To solve this you could do two things, fix the logic in your app to persist the logout state, so you don't try and log out when the user is not actually logged in anymore. Or you could enable the ActiveToken and add an if statement before trying to log out to verify if it's null or not you can do so by following the steps on the getting started guide on the project repo: https://github.com/CrossGeeks/GoogleClientPlugin/blob/master/GoogleClient/docs/GettingStarted.md

Activate ActiveToken Google Client Plugin Guide Screenshot