Skip to content

Commit

Permalink
add support for directLoginAction callback listener
Browse files Browse the repository at this point in the history
  • Loading branch information
frontegg-david committed Sep 2, 2024
1 parent 09da9e7 commit 506aadc
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ class EmbeddedAuthActivity : Activity() {
Log.d(TAG, "isAuthenticatedConsumer: ${it.value}")
if (it.value) {
runOnUiThread {
onAuthFinishedCallback?.invoke()
navigateToAuthenticated()
}
}
Expand All @@ -140,6 +141,9 @@ class EmbeddedAuthActivity : Activity() {


if (directLoginLaunchedDone) {
onAuthFinishedCallback?.invoke()
FronteggAuth.instance.isLoading.value = false
FronteggAuth.instance.showLoader.value = false
setResult(RESULT_OK)
finish()
return
Expand Down Expand Up @@ -177,6 +181,8 @@ class EmbeddedAuthActivity : Activity() {
const val DIRECT_LOGIN_ACTION_DATA = "com.frontegg.android.DIRECT_LOGIN_ACTION_DATA"
private const val AUTH_LAUNCHED = "com.frontegg.android.AUTH_LAUNCHED"
private val TAG = EmbeddedAuthActivity::class.java.simpleName
var onAuthFinishedCallback: (() -> Unit)? = null // Store callback


fun authenticate(activity: Activity) {
val intent = Intent(activity, EmbeddedAuthActivity::class.java)
Expand All @@ -187,12 +193,13 @@ class EmbeddedAuthActivity : Activity() {
activity.startActivityForResult(intent, OAUTH_LOGIN_REQUEST)
}

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

intent.putExtra(DIRECT_LOGIN_ACTION_LAUNCHED, true)
intent.putExtra(DIRECT_LOGIN_ACTION_TYPE, type)
intent.putExtra(DIRECT_LOGIN_ACTION_DATA, data)
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 @@ -354,9 +354,9 @@ class FronteggAuth(
}
}

fun directLoginAction(activity: Activity, type: String, data: String) {
fun directLoginAction(activity: Activity, type: String, data: String, callback: (() -> Unit)? = null) {
if (FronteggApp.getInstance().isEmbeddedMode) {
EmbeddedAuthActivity.directLoginAction(activity, type, data)
EmbeddedAuthActivity.directLoginAction(activity, type, data, callback)
} else {
Log.w(TAG, "Direct login action is not supported in non-embedded mode")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ class FronteggNativeBridge(val context: Context) {

val authorizationUrl = Uri.parse(generatedUrl.first)

Log.d("FronteggNativeBridge", "directLoginWithContext(${authorizationUrl})")
if (FronteggApp.getInstance().useChromeCustomTabs) {
val customTabsIntent = CustomTabsIntent.Builder().setShowTitle(false).build()
customTabsIntent.intent.setPackage("com.android.chrome");
Expand Down
6 changes: 5 additions & 1 deletion embedded/src/main/java/com/frontegg/demo/AuthFragment.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.frontegg.demo

import android.os.Bundle
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
Expand Down Expand Up @@ -41,7 +42,10 @@ class AuthFragment : Fragment() {

binding.googleLoginButton.setOnClickListener {

FronteggAuth.instance.directLoginAction(requireActivity(), "social-login", "google")
FronteggAuth.instance.directLoginAction(requireActivity(), "social-login", "google", callback = {

Log.d("AuthFragment", "Direct login action callback")
})
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class NavigationActivity : AppCompatActivity() {
private var lastVisibilityState = View.VISIBLE
private val onShowLoaderChange: Consumer<NullableObject<Boolean>> = Consumer {

Log.d(TAG, "showLoader: ${it.value}")
Log.d(TAG, "showLoader: ${it.value}, initializing: ${FronteggAuth.instance.initializing.value}")
runOnUiThread {
if (it.value) {
supportActionBar?.hide()
Expand Down

0 comments on commit 506aadc

Please sign in to comment.