Skip to content

Commit

Permalink
Add experimental support for IOS native targets (#53)
Browse files Browse the repository at this point in the history
  • Loading branch information
jan-tennert committed Apr 6, 2023
1 parent 03967e2 commit 73f1b30
Show file tree
Hide file tree
Showing 17 changed files with 96 additions and 27 deletions.
7 changes: 6 additions & 1 deletion Functions/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ kotlin {
}
}
}
//ios()
ios()
iosSimulatorArm64()
sourceSets {
all {
languageSettings.optIn("kotlin.RequiresOptIn")
Expand All @@ -46,6 +47,10 @@ kotlin {
val jvmMain by getting
val androidMain by getting
val jsMain by getting
val iosMain by getting
val iosSimulatorArm64Main by getting {
dependsOn(iosMain)
}
}
}

Expand Down
12 changes: 10 additions & 2 deletions GoTrue/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ kotlin {
}
}
}
//ios()
ios()
iosSimulatorArm64()
sourceSets {
all {
languageSettings.optIn("kotlin.RequiresOptIn")
Expand Down Expand Up @@ -63,7 +64,14 @@ kotlin {
}
}
val jsMain by getting
//val iosMain by getting
val iosMain by getting
val iosTest by getting
val iosSimulatorArm64Main by getting {
dependsOn(iosMain)
}
val iosSimulatorArm64Test by getting {
dependsOn(iosTest)
}
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package io.github.jan.supabase.gotrue

import io.github.jan.supabase.plugins.MainConfig

actual class GoTrueConfig : MainConfig, GoTrueConfigDefaults() {

/**
* The scheme for the redirect url, when using deep linking
*/
var scheme: String = "supabase"

/**
* The host for the redirect url, when using deep linking
*/
var host: String = "login"

}
12 changes: 0 additions & 12 deletions GoTrue/src/iosMain/kotlin/io/github/jan/supabase/gotrue/IOS.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,6 @@ import io.github.jan.supabase.gotrue.user.UserSession
import platform.Foundation.NSURL
import platform.Foundation.NSURLComponents

var GoTrue.Config.scheme: String
get() = (params["scheme"] as? String) ?: "supabase"
set(value) {
params["scheme"] = value
}

var GoTrue.Config.host: String
get() = (params["host"] as? String) ?: "login"
set(value) {
params["host"] = value
}

@SupabaseExperimental
fun SupabaseClient.handleDeeplinks(url: NSURL, onSessionSuccess: (UserSession) -> Unit = {}) {
val components = NSURLComponents(url, true)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package io.github.jan.supabase.gotrue

actual fun GoTrue.generateRedirectUrl(fallbackUrl: String?): String? {
if(fallbackUrl != null) return fallbackUrl
this as GoTrueImpl
return "${config.scheme}://${config.host}"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package io.github.jan.supabase.gotrue.providers

actual class ExternalAuthConfig
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,13 @@ package io.github.jan.supabase.gotrue.providers
import io.github.aakira.napier.Napier
import io.github.jan.supabase.SupabaseClient
import io.github.jan.supabase.gotrue.gotrue
import io.github.jan.supabase.gotrue.host
import io.github.jan.supabase.gotrue.scheme
import io.github.jan.supabase.gotrue.user.UserSession
import platform.Foundation.NSURL
import platform.UIKit.UIApplication

actual abstract class OAuthProvider : AuthProvider<ExternalAuthConfig, Unit> {

actual abstract fun provider(): String
actual abstract val name: String

actual override suspend fun login(
supabaseClient: SupabaseClient,
Expand All @@ -34,7 +32,7 @@ actual abstract class OAuthProvider : AuthProvider<ExternalAuthConfig, Unit> {
private fun openOAuth(redirectUrl: String? = null, supabaseClient: SupabaseClient) {
val gotrue = supabaseClient.gotrue
val deepLink = "${gotrue.config.scheme}://${gotrue.config.host}"
val url = NSURL(supabaseClient.gotrue.resolveUrl("authorize?provider=${provider()}&redirect_to=${redirectUrl ?: deepLink}"))
val url = NSURL(string = supabaseClient.gotrue.resolveUrl("authorize?provider=$name&redirect_to=${redirectUrl ?: deepLink}"))
UIApplication.sharedApplication.openURL(url, emptyMap<Any?, Any>()) {
if(it) Napier.d { "Successfully opened provider url in safari" } else Napier.e { "Failed to open provider url in safari" }
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package io.github.jan.supabase.gotrue

import io.github.aakira.napier.Napier

actual fun GoTrue.setupPlatform() {
Napier.w { "IOS support is highly experimental, please report any bugs you find!" }
}
4 changes: 4 additions & 0 deletions GoTrue/src/iosTest/kotlin/platformSettings.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import io.github.jan.supabase.gotrue.GoTrueConfig

actual fun GoTrueConfig.platformSettings() {
}

This file was deleted.

7 changes: 6 additions & 1 deletion Postgrest/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ kotlin {
}
}
}
//ios()
ios()
iosSimulatorArm64()
sourceSets {
all {
languageSettings.optIn("kotlin.RequiresOptIn")
Expand All @@ -50,6 +51,10 @@ kotlin {
val jvmMain by getting
val androidMain by getting
val jsMain by getting
val iosMain by getting
val iosSimulatorArm64Main by getting {
dependsOn(iosMain)
}
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package io.github.jan.supabase.postgrest

import kotlin.reflect.KProperty1

actual fun <T, V> getColumnName(property: KProperty1<T, V>) = property.name
7 changes: 6 additions & 1 deletion Realtime/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ kotlin {
}
}
}
//ios()
ios()
iosSimulatorArm64()
sourceSets {
all {
languageSettings.optIn("kotlin.RequiresOptIn")
Expand All @@ -49,6 +50,10 @@ kotlin {
val jvmMain by getting
val androidMain by getting
val jsMain by getting
val iosMain by getting
val iosSimulatorArm64Main by getting {
dependsOn(iosMain)
}
}
}

Expand Down
7 changes: 6 additions & 1 deletion Storage/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ kotlin {
}
}
}
//ios()
ios()
iosSimulatorArm64()
sourceSets {
all {
languageSettings.optIn("kotlin.RequiresOptIn")
Expand All @@ -49,6 +50,10 @@ kotlin {
dependsOn(nonJsMain)
}
val jsMain by getting
val iosMain by getting
val iosSimulatorArm64Main by getting {
dependsOn(iosMain)
}
}
}

Expand Down
11 changes: 10 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,8 @@ kotlin {
}
}
}
//ios()
ios()
iosSimulatorArm64()
sourceSets {
all {
languageSettings.optIn("kotlin.RequiresOptIn")
Expand Down Expand Up @@ -151,6 +152,14 @@ kotlin {
// api(compose.web.core)
}
}
val iosTest by getting
val iosMain by getting
val iosSimulatorArm64Main by getting {
dependsOn(iosMain)
}
val iosSimulatorArm64Test by getting {
dependsOn(iosTest)
}
}
}

Expand Down
7 changes: 6 additions & 1 deletion plugins/ApolloGraphQL/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ kotlin {
}
}
}
//ios()
ios()
iosSimulatorArm64()
sourceSets {
all {
languageSettings.optIn("kotlin.RequiresOptIn")
Expand All @@ -51,6 +52,10 @@ kotlin {
val jvmMain by getting
val androidMain by getting
val jsMain by getting
val iosMain by getting
val iosSimulatorArm64Main by getting {
dependsOn(iosMain)
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/jsMain/kotlin/io/github/jan/supabase/PlatformTarget.kt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
package io.github.jan.supabase

actual val CurrentPlatformTarget = PlatformTarget.WEB
actual val CurrentPlatformTarget: PlatformTarget = PlatformTarget.WEB

0 comments on commit 73f1b30

Please sign in to comment.