Skip to content

Commit

Permalink
add support for callback using standard login activity
Browse files Browse the repository at this point in the history
  • Loading branch information
frontegg-david committed Oct 4, 2024
1 parent f25d744 commit 605bb91
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -186,12 +186,13 @@ class EmbeddedAuthActivity : Activity() {
var onAuthFinishedCallback: (() -> Unit)? = null // Store callback


fun authenticate(activity: Activity) {
fun authenticate(activity: Activity, callback: (() -> Unit)? = null) {
val intent = Intent(activity, EmbeddedAuthActivity::class.java)

val authorizeUri = AuthorizeUrlGenerator().generate()
intent.putExtra(AUTH_LAUNCHED, true)
intent.putExtra(AUTHORIZE_URI, authorizeUri.first)
onAuthFinishedCallback = callback
activity.startActivityForResult(intent, OAUTH_LOGIN_REQUEST)
}

Expand Down
4 changes: 2 additions & 2 deletions android/src/main/java/com/frontegg/android/FronteggAuth.kt
Original file line number Diff line number Diff line change
Expand Up @@ -347,9 +347,9 @@ class FronteggAuth(

}

fun login(activity: Activity) {
fun login(activity: Activity, callback: (() -> Unit)? = null) {
if (FronteggApp.getInstance().isEmbeddedMode) {
EmbeddedAuthActivity.authenticate(activity)
EmbeddedAuthActivity.authenticate(activity, callback)
} else {
AuthenticationActivity.authenticate(activity)
}
Expand Down
4 changes: 3 additions & 1 deletion embedded/src/main/java/com/frontegg/demo/AuthFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ class AuthFragment : Fragment() {
super.onViewCreated(view, savedInstanceState)

binding.loginButton.setOnClickListener {
FronteggAuth.instance.login(requireActivity())
FronteggAuth.instance.login(requireActivity()) {
Log.d("AuthFragment", "Login callback")
}
}

binding.googleLoginButton.setOnClickListener {
Expand Down

0 comments on commit 605bb91

Please sign in to comment.