Skip to content
This repository has been archived by the owner on Sep 27, 2024. It is now read-only.

Commit

Permalink
Add user profile function
Browse files Browse the repository at this point in the history
  • Loading branch information
Steve Hobbs authored and lbalmaceda committed Feb 11, 2021
1 parent 48880fa commit 9fb75d8
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
28 changes: 27 additions & 1 deletion 00-Login-Kt/app/src/main/java/com/auth0/sample/MainActivity.kt
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
package com.auth0.sample

import android.os.Bundle
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import com.auth0.android.Auth0
import com.auth0.android.Auth0Exception
import com.auth0.android.authentication.AuthenticationAPIClient
import com.auth0.android.authentication.AuthenticationException
import com.auth0.android.callback.Callback
import com.auth0.android.provider.VoidCallback
import com.auth0.android.provider.WebAuthProvider
import com.auth0.android.result.Credentials
import com.auth0.android.result.UserProfile
import com.auth0.sample.databinding.ActivityMainBinding
import com.google.android.material.snackbar.Snackbar

Expand Down Expand Up @@ -55,6 +57,8 @@ class MainActivity : AppCompatActivity() {
"Success: ${credentials?.accessToken}",
Snackbar.LENGTH_LONG
).show()

showUserInfo(payload)
}
})
}
Expand All @@ -77,4 +81,26 @@ class MainActivity : AppCompatActivity() {
})
}

private fun showUserInfo(credentials: Credentials?) {
var client = AuthenticationAPIClient(account)

credentials?.accessToken?.let {
client.userInfo(it)
.start(object : Callback<UserProfile, AuthenticationException> {
override fun onFailure(error: AuthenticationException) {
Snackbar.make(
binding.root,
"Failure: ${error.getCode()}",
Snackbar.LENGTH_LONG
).show()
}

override fun onSuccess(payload: UserProfile?) {
binding.userProfile.setText(
"Name: ${payload?.name}\n" +
"Email: ${payload?.email}")
}
}) }
}

}
10 changes: 9 additions & 1 deletion 00-Login-Kt/app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
android:id="@+id/button_logout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="36dp"
android:text="Log out"
app:layout_constraintEnd_toEndOf="@+id/textView"
app:layout_constraintStart_toStartOf="@+id/textView"
Expand All @@ -37,4 +36,13 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<TextView
android:id="@+id/userProfile"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/button_logout"
android:layout_margin="36dp"/>

</androidx.constraintlayout.widget.ConstraintLayout>

0 comments on commit 9fb75d8

Please sign in to comment.