Tấn Nguyễn
Tấn Nguyễn

Reputation: 1

Keep Login State Account Kit

I login on the Account Kit successfully, but when I close the application and re-enter it, I have to log in again, is there a way to help me save my login? Thanks a lot.

Upvotes: -2

Views: 66

Answers (1)

Esh
Esh

Reputation: 535

I understand that you have not provided adequate code for us to assist. But here are a few basic pointers for you to work around:

  1. Account Kit returns a AuthCode or Access Token
  2. On opening the app, check if the AuthCode exists. If it doesn't, you need to call the login method.

    if (AccountKit.getCurrentAccessToken() != null) {
        startActivity(new Intent(this, YourDestinationActivity.class));} 
    else {onLogin(LoginType.PHONE);}
    

If user is logged in previously, it starts the destination activity. If not, it starts the onLogin() method and logs in with the phone number.

Your onLogin might look something like this:

private void onLogin(LoginType phone) {
 final Intent intent = new Intent(this, AccountKitActivity.class);
 AccountKitConfiguration.AccountKitConfigurationBuilder configurationBuilder = new AccountKitConfiguration.AccountKitConfigurationBuilder(LoginType.PHONE, AccountKitActivity.ResponseType.TOKEN);
 uiManager = new SkinManager(SkinManager.Skin.CONTEMPORARY, Color.parseColor("#EC1D24"));
 configurationBuilder.setUIManager(uiManager);
 intent.putExtra(AccountKitActivity.ACCOUNT_KIT_ACTIVITY_CONFIGURATION, configurationBuilder.build());
 startActivityForResult(intent, REQUEST_CODE);
}

Go through this or this to understand how this works in a much better way.

Upvotes: 0

Related Questions