I am using the supabase-kt library to add Sign In via Apple to my Android app. In this case, the library falls back to a Web-based OAuth flow, which is launched in a Custom Tab. Everything works fine at this point: I can sign in successfully and control is returned to my app via a Deep Link. But one issue remains: The Custom Tab hosting the OAuth flow is not terminated and it shows up in Recents (Task Manager.)
I have tried setting launchMode to singleTask, singleTop, singleInstance for the Activity that receives the Deep Link, and tried with Chrome and Firefox as default browsers so that the corresponding Custom Tab implementation is used, but nothing changes: the Custom Tab persists after the OAuth flow ends.
I am using supabase-kt version 3.1.4, and unfortunately I can't upgrade at this point in time. However, I have compared the supabase-kt source code for 3.1.4 and master, and they are identical when it comes to the use of Custom Tabs.
internal fun openUrl(uri: Uri, action: ExternalAuthAction) {
when(action) {
ExternalAuthAction.ExternalBrowser -> {
val browserIntent = Intent(Intent.ACTION_VIEW, uri)
browserIntent.flags = Intent.FLAG_ACTIVITY_NEW_TASK
applicationContext().startActivity(browserIntent)
}
is ExternalAuthAction.CustomTabs -> {
val intent = CustomTabsIntent.Builder().apply(action.intentBuilder).build()
intent.intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK
intent.launchUrl(applicationContext(), uri)
}
}
}
I do see that ExternalAuthAction has this:
data class CustomTabs(val intentBuilder: CustomTabsIntent.Builder.() -> Unit = {}) : ExternalAuthAction
Is there something I can set via CustomTabsIntent.Builder that will ensure that the Custom Tab is terminated after the Web OAuth flow finishes successfully? Or perhaps the intent.intent.flags need to be different (I see some reports indicating that FLAG_ACTIVITY_NO_HISTORY sometimes helps)? Or I am missing something else in my use of supabase-kt?
Any pointer would be greatly appreciated.
The user is experiencing an issue where the Custom Tab used for OAuth in their Android app does not close after the authentication flow completes. They are using the supabase-kt library and have tried various configurations without success. A workaround was suggested by Jan Tennert to manually handle the OAuth URL opening.
@eb-ib Both of the issues you pointed out will be fixed in #1278 (the overriding & history). If you can't upgrade you have to mimic the functionality: Get the OAuth url like this:
val urlToOpen = supabaseClient.auth.getOAuthUrl(Provider, deeplink)
Then just open the url correctly as a temporary workaround.