Skip to content

Commit fe22c68

Browse files
committed
Add support for providing a custom url launcher
1 parent 898c25b commit fe22c68

File tree

7 files changed

+42
-6
lines changed

7 files changed

+42
-6
lines changed

Auth/src/androidMain/kotlin/io/github/jan/supabase/auth/Utils.android.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,5 @@ internal actual suspend fun Auth.startExternalAuth(
1414
getUrl: suspend (redirectTo: String?) -> String,
1515
onSessionSuccess: suspend (UserSession) -> Unit
1616
) {
17-
supabaseClient.openExternalUrl(getUrl(redirectUrl))
17+
config.urlLauncher.openUrl(supabaseClient, getUrl(redirectUrl))
1818
}

Auth/src/commonMain/kotlin/io/github/jan/supabase/auth/AuthConfig.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package io.github.jan.supabase.auth
22

33
import io.github.jan.supabase.SupabaseClientBuilder
44
import io.github.jan.supabase.SupabaseSerializer
5+
import io.github.jan.supabase.annotations.SupabaseExperimental
56
import io.github.jan.supabase.plugins.CustomSerializationConfig
67
import io.github.jan.supabase.plugins.MainConfig
78
import kotlinx.coroutines.CoroutineDispatcher
@@ -96,6 +97,12 @@ open class AuthConfigDefaults : MainConfig() {
9697
*/
9798
var enableLifecycleCallbacks: Boolean = true
9899

100+
/**
101+
* The URL launcher used to open OAuth links in the system browser.
102+
*/
103+
@SupabaseExperimental
104+
var urlLauncher: UrlLauncher = UrlLauncher.DEFAULT
105+
99106
}
100107

101108
/**
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package io.github.jan.supabase.auth
2+
3+
import io.github.jan.supabase.SupabaseClient
4+
import io.github.jan.supabase.annotations.SupabaseExperimental
5+
6+
/**
7+
* A [UrlLauncher] is used to open a URL in the system browser.
8+
*/
9+
@SupabaseExperimental
10+
fun interface UrlLauncher {
11+
12+
/**
13+
* Open the given URL in the system browser.
14+
* @param url The URL to open.
15+
*/
16+
suspend fun openUrl(supabase: SupabaseClient, url: String)
17+
18+
companion object {
19+
20+
/**
21+
* Default implementation of [UrlLauncher] that opens the URL in the system browser.
22+
*/
23+
val DEFAULT = UrlLauncher { supabase, url ->
24+
supabase.openExternalUrl(url)
25+
}
26+
27+
}
28+
29+
}

Auth/src/desktopMain/kotlin/io/github/jan/supabase/auth/Utils.desktop.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ internal actual suspend fun Auth.startExternalAuth(
1313
) {
1414
withContext(Dispatchers.IO) {
1515
if(redirectUrl != null) {
16-
supabaseClient.openExternalUrl(getUrl(redirectUrl))
16+
config.urlLauncher.openUrl(supabaseClient, getUrl(redirectUrl))
1717
return@withContext
1818
}
1919
createServer({

Auth/src/desktopMain/kotlin/io/github/jan/supabase/auth/server/HttpCallbackServer.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package io.github.jan.supabase.auth.server
22

33
import io.github.jan.supabase.auth.Auth
44
import io.github.jan.supabase.auth.AuthImpl
5-
import io.github.jan.supabase.auth.openExternalUrl
65
import io.github.jan.supabase.auth.user.UserSession
76
import io.github.jan.supabase.logging.d
87
import io.ktor.http.ContentType
@@ -42,7 +41,8 @@ internal suspend fun createServer(
4241
Auth.logger.d {
4342
"Started OAuth callback server on port $port. Opening url in browser..."
4443
}
45-
auth.supabaseClient.openExternalUrl(
44+
auth.config.urlLauncher.openUrl(
45+
auth.supabaseClient,
4646
url(
4747
"http://localhost:$port"
4848
)

Auth/src/nonDesktopMain/kotlin/io/github/jan/supabase/auth/Utils.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@ internal actual suspend fun Auth.startExternalAuth(
88
getUrl: suspend (redirectTo: String?) -> String,
99
onSessionSuccess: suspend (UserSession) -> Unit
1010
) {
11-
supabaseClient.openExternalUrl(getUrl(redirectUrl))
11+
config.urlLauncher.openUrl(supabaseClient, getUrl(redirectUrl))
1212
}

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,5 @@ org.jetbrains.compose.experimental.jscanvas.enabled=true
1111
org.jetbrains.compose.experimental.wasm.enabled=true
1212
org.jetbrains.dokka.experimental.gradle.pluginMode=V2Enabled
1313

14-
supabase-version = 3.2.0-beta-1
14+
supabase-version = 3.2.0-beta-2
1515
base-group = io.github.jan-tennert.supabase

0 commit comments

Comments
 (0)