iZettle / sdk-android

Add card payments from Zettle to your own app
https://developer.zettle.com/docs/android-sdk
24 stars 20 forks source link

How can I get user info from a user that is already logged in without make a Payment first? #28

Closed fershopls closed 2 years ago

fershopls commented 3 years ago

Expected Behavior

Open the app. User login succesfully. Close the app.

Reopen the app. Attempt to get user info. Get user info successfully.

Everything ok!

Current Behavior

I can only get user info after start activity for result with CardPaymentActivity.IntentBuilder intent. The auth observer with the LoggedIn object its being triggered after this.

Open the app. User login succesfully. Close the app.

Open the app.

Attempt to get user info. Failed because the user is not logged in.

Attempt to make a payment Attempt to get user info. Get user info successfully.

How can I get user info from a user that is already logged in?

bobzettle commented 2 years ago

Hi, apologies for not hearing from us. Have you managed to sort this out?

Otherwise when observing the IZettleSDK.user.state.toLiveData() you will get an AuthState back. If that state is logged in, you'll be able to extract the user info from that state.

A bit of sample code:

IZettleSDK.user.state.toLiveData().observe(this, { state ->
    when(state) {
        is LoggedIn -> state.info // here is your User.Info object.
    }
})

Hope that helps.