### Start Uploading Source: https://github.com/supabase-community/supabase-kt/wiki/Storage/Resumable uploads Initiates or resumes the upload process. ```kotlin upload.startOrResumeUploading() ``` -------------------------------- ### Initialize Realtime plugin Source: https://github.com/supabase-community/supabase-kt/blob/master/Realtime/README.md Install the Realtime plugin within the SupabaseClient configuration block. ```kotlin val supabase = createSupabaseClient( supabaseUrl = "https://id.supabase.co", supabaseKey = "apikey" ) { //... install(Realtime) { // settings } } ``` -------------------------------- ### Initialize Auth Plugin Source: https://github.com/supabase-community/supabase-kt/blob/master/Auth/README.md Install the Auth plugin within the SupabaseClient configuration block. ```kotlin val supabase = createSupabaseClient( supabaseUrl = "https://id.supabase.co", supabaseKey = "apikey" ) { //... install(Auth) { // settings } } ``` -------------------------------- ### Install Custom Plugin Source: https://github.com/supabase-community/supabase-kt/wiki/Creating-Plugins Register the custom plugin during the Supabase client initialization using the install function. ```kotlin val client = createSupabaseClient(supabaseUrl = "...", supabaseKey = "...") { install(MyPlugin) { someSetting = true } } ``` -------------------------------- ### Initialize Functions Plugin Source: https://github.com/supabase-community/supabase-kt/wiki/Functions/Functions Install the Functions plugin within the main Supabase client configuration. ```kotlin val client = createSupabaseClient(supabaseUrl = "...", supabaseKey = "...") { //... install(Functions) { // settings } } ``` -------------------------------- ### Configure Realtime plugin Source: https://github.com/supabase-community/supabase-kt/wiki/Realtime/Realtime Install the Realtime plugin within the main Supabase client instance. ```kotlin val client = createSupabaseClient(supabaseUrl = "...", supabaseKey = "...") { //... install(Realtime) { // settings } } ``` -------------------------------- ### Initialize SupabaseClient with Storage Plugin Source: https://github.com/supabase-community/supabase-kt/blob/master/Storage/README.md Install the Storage plugin when creating your SupabaseClient instance. This enables storage-specific functionalities. ```kotlin val supabase = createSupabaseClient( supabaseUrl = "https://id.supabase.co", supabaseKey = "apikey" ) { //... install(Storage) { // settings } } ``` -------------------------------- ### Create Basic Supabase Client Source: https://github.com/supabase-community/supabase-kt/wiki/Getting-Started Initializes the Supabase client with your project URL and API key. This is the first step before installing any modules. ```kotlin val client = createSupabaseClient( supabaseUrl = "https://PROJECT_ID.supabase.co", supabaseKey = "YOUR_KEY" ) ``` -------------------------------- ### Install Functions Plugin in SupabaseClient Source: https://github.com/supabase-community/supabase-kt/blob/master/Functions/README.md Install the Functions plugin when creating your SupabaseClient. This enables the Functions client functionality. Refer to the Supabase-kt documentation for more initialization details. ```kotlin val client = createSupabaseClient( supabaseUrl = "https://id.supabase.co", supabaseKey = "apikey" ) { //... install(Functions) { // settings } } ``` -------------------------------- ### Install ImageLoaderIntegration Plugin in SupabaseClient Source: https://github.com/supabase-community/supabase-kt/blob/master/plugins/ImageLoaderIntegration/README.md Install the ImageLoaderIntegration plugin when creating your SupabaseClient. This enables image loading capabilities. ```kotlin val client = createSupabaseClient( supabaseUrl = "https://id.supabase.co", supabaseKey = "apikey" ) { //... install(Storage) { //your config } install(ImageLoaderIntegration) } ``` -------------------------------- ### Access Postgrest plugin Source: https://github.com/supabase-community/supabase-kt/wiki/Postgrest/Postgrest Access the installed Postgrest plugin instance from the client. ```kotlin client.postgrest ``` -------------------------------- ### Install GoTrue Module Source: https://github.com/supabase-community/supabase-kt/wiki/Getting-Started Installs the GoTrue module into the Supabase client. Ensure the GoTrue plugin is added to your project dependencies. ```kotlin val client = createSupabaseClient( supabaseUrl = "https://PROJECT_ID.supabase.co", supabaseKey = "YOUR_KEY" ) { install(GoTrue) } ``` -------------------------------- ### Install Postgrest plugin in Supabase client Source: https://github.com/supabase-community/supabase-kt/wiki/Postgrest/Postgrest Configure the Postgrest plugin within the main Supabase client instance. ```kotlin val client = createSupabaseClient(supabaseUrl = "...", supabaseKey = "...") { //... install(Postgrest) { // settings } } ``` -------------------------------- ### Install Postgrest Plugin in SupabaseClient Source: https://github.com/supabase-community/supabase-kt/blob/master/Postgrest/README.md Integrate the Postgrest plugin into your SupabaseClient instance during initialization. Refer to the Supabase documentation for more details on client initialization. ```kotlin val supabase = createSupabaseClient( supabaseUrl = "https://id.supabase.co", supabaseKey = "apikey" ) { //... install(Postgrest) { // settings } } ``` -------------------------------- ### Install Auth Dependency Source: https://github.com/supabase-community/supabase-kt/blob/master/Auth/README.md Add the auth-kt dependency to your project's build configuration. ```kotlin dependencies { implementation("io.github.jan-tennert.supabase:auth-kt:VERSION") } ``` -------------------------------- ### Access Storage Plugin Source: https://github.com/supabase-community/supabase-kt/wiki/Storage/Storage Access the Storage plugin's functionalities through the client instance after installation. ```kotlin client.storage ``` -------------------------------- ### Configure GoTrue plugin Source: https://github.com/supabase-community/supabase-kt/wiki/GoTrue/GoTrue Install the GoTrue plugin within the main Supabase client initialization block. ```kotlin val client = createSupabaseClient(supabaseUrl = "...", supabaseKey = "...") { //... install(GoTrue) { // settings } } ``` -------------------------------- ### Install Realtime dependency Source: https://github.com/supabase-community/supabase-kt/blob/master/Realtime/README.md Add the Realtime library to your project dependencies using the specified version. ```kotlin dependencies { implementation("io.github.jan-tennert.supabase:realtime-kt:VERSION") } ``` -------------------------------- ### Create Supabase Client Source: https://github.com/supabase-community/supabase-kt/blob/master/Supabase/README.md Instantiate a Supabase client with your project's URL and API key. You can customize default settings like serializer and log level, and install plugins like Auth. ```kotlin //Create a Supabase client val supabase = createSupabaseClient( supabaseUrl = "https://id.supabase.co", supabaseKey = "apikey" ) { //Change default settings defaultSerializer = MyCustomSerializer() defaultLogLevel = LogLevel.DEBUG //Install a plugin install(Auth) //from auth-kt } //Access a plugin via the client val auth = supabase.auth ``` -------------------------------- ### Install Storage Plugin in Supabase Client Source: https://github.com/supabase-community/supabase-kt/wiki/Storage/Storage Integrate the Storage plugin into your main Supabase client configuration. Ensure you have other necessary configurations like authentication if needed. ```kotlin val client = createSupabaseClient( { //... install(Storage) { // settings } } ``` -------------------------------- ### Create and join a channel Source: https://github.com/supabase-community/supabase-kt/wiki/Realtime/Realtime Define a channel with presence or broadcast options and join it to start receiving events. ```kotlin val channel = supabaseClient.realtime.createChannel("#random") { presence { //presence options } broadcast { //broadcast options } } //after you called methods like broadcastFlow or postgrestChangeFlow, join the channel: channel.join() ``` -------------------------------- ### Multiplatform Ktor Client Engine Setup Source: https://github.com/supabase-community/supabase-kt/blob/master/README.md Configure Ktor client engines for different Kotlin targets (JVM, Android, JS, iOS) within your source sets. Ensure you use the appropriate Ktor version. ```kotlin sourceSets { commonMain { dependencies { //Supabase modules } } jvmMain { dependencies { implementation("io.ktor:ktor-client-cio:KTOR_VERSION") } } androidMain { dependsOn(jvmMain.get()) } jsMain { dependencies { implementation("io.ktor:ktor-client-js:KTOR_VERSION") } } iosMain { dependencies { implementation("io.ktor:ktor-client-darwin:KTOR_VERSION") } } } ``` -------------------------------- ### Login with GoTrue Module Source: https://github.com/supabase-community/supabase-kt/wiki/Getting-Started Uses the GoTrue module's extension property to log in a user with email and password. Requires the GoTrue plugin to be installed. ```kotlin client.gotrue.loginWith(Email) { email = "example@email.com" password = "12345" } ``` -------------------------------- ### Install GoTrue dependency Source: https://github.com/supabase-community/supabase-kt/blob/master/GoTrue/README.md Add the GoTrue dependency to your project's build configuration. ```kotlin dependencies { implementation("io.github.jan-tennert.supabase:gotrue-kt:VERSION") } ``` -------------------------------- ### OAuth Login for Desktop Apps with Supabase Kotlin Source: https://github.com/supabase-community/supabase-kt/wiki/GoTrue/Login Implement OAuth login for desktop applications by installing the `GoTrue` plugin and calling `loginWith` with the desired provider. Ensure redirect URLs are configured in Supabase. ```kotlin suspend fun main() { val client = createSupabaseClient( supabaseUrl = System.getenv("SUPABASE_URL"), supabaseKey = System.getenv("SUPABASE_KEY") ) { install(GoTrue) { //as of 0.8.0 timeout = 50.seconds htmlTitle = "Supabase" htmlText = "Logged in. You may continue in the app." } } client.gotrue.loginWith(Discord) } ``` -------------------------------- ### OAuth Login for Web Apps with Supabase Kotlin Source: https://github.com/supabase-community/supabase-kt/wiki/GoTrue/Login Implement OAuth login for web applications by creating a Supabase client and calling `loginWith` with the desired provider. Ensure the `GoTrue` plugin is installed. ```kotlin val client = createSupabaseClient(supabaseUrl = "...", supabaseKey = "...") { supabaseUrl = "" supabaseKey = "" install(GoTrue) } //somewhere in an onClick callback: client.gotrue.loginWith(Discord) ``` -------------------------------- ### Configure GoTrue Module with Custom URL Source: https://github.com/supabase-community/supabase-kt/wiki/Getting-Started Installs and configures the GoTrue module with a custom authentication URL. This allows for advanced routing or custom backends. ```kotlin val client = createSupabaseClient( supabaseUrl = "https://PROJECT_ID.supabase.co", supabaseKey = "YOUR_KEY" ) { install(GoTrue) { customUrl = "https://my-custom-auth-url.com" } } ``` -------------------------------- ### Create a storage bucket Source: https://github.com/supabase-community/supabase-kt/wiki/Storage/Managing Buckets Initializes a new storage bucket with specific configuration options like public access and file constraints. ```kotlin client.storage.createBucket(name = "images", id = "images") { public = true fileSizeLimit = 20.megabytes allowedMimeTypes(ContentType.Image.JPG, ContentType.Image.PNG) } ``` -------------------------------- ### Run Desktop Build Source: https://github.com/supabase-community/supabase-kt/blob/master/sample/chat-demo-mpp/README.md Command to run the distributable version of the chat app on Desktop. ```bash ./gradlew :sample:chat-demo-mpp:desktop:runDistributable ``` -------------------------------- ### Initialize Supabase Client Source: https://github.com/supabase-community/supabase-kt/wiki/GoTrue/Admin API Configures the client with URL and key, and imports the service role secret for administrative access. ```kotlin val client = createSupabaseClient(supabaseUrl = "...", supabaseKey = "...") { //[...] install(GoTrue) { alwaysAutoRefresh = false autoLoadFromStorage = false } } client.gotrue.importAuthToken("service role secret") ``` -------------------------------- ### Sign up with phone Source: https://github.com/supabase-community/supabase-kt/wiki/GoTrue/Signup Registers a new user using a phone number and password. Requires verification via OTP. ```kotlin val result = supabaseClient.gotrue.signUpWith(Phone) { phoneNumber = "123456" password = "12345" } println(result.id) ``` -------------------------------- ### Sign up with email Source: https://github.com/supabase-community/supabase-kt/wiki/GoTrue/Signup Registers a new user using an email address and password. Note that users are not automatically logged in by default. ```kotlin val result = supabaseClient.gotrue.signUpWith(Email) { email = "example@email.com" password = "12345" } println(result.id) ``` -------------------------------- ### Sign up with provider Source: https://github.com/supabase-community/supabase-kt/wiki/GoTrue/Signup Initiates a sign-up flow using an external OAuth provider like Google. ```kotlin supabaseClient.gotrue.signUpWith(Google) ``` -------------------------------- ### Configure Storage Download Options with Image Transformations Source: https://github.com/supabase-community/supabase-kt/blob/master/MIGRATION.md Use the options DSL for downloading files, allowing configuration of image transformations such as resizing. ```kotlin supabase.storage.from("test").downloadAuthenticated("test.jpg") { transform { size(100, 100) } } ``` -------------------------------- ### GET /messages (Select) Source: https://github.com/supabase-community/supabase-kt/wiki/Make-Database-Calls Retrieves records from the messages table with optional filtering and column selection. ```APIDOC ## GET /messages ### Description Retrieves records from the messages table. Supports filtering using property references or string-based column names and column restriction. ### Method GET ### Endpoint /messages ### Parameters #### Query Parameters - **filters** (Object) - Optional - Filters applied via property references (e.g., Message::authorId eq "someid") or explicit column methods (eq, neq, isIn). - **columns** (Columns) - Optional - Restricts returned columns using Columns.type() or Columns.list(). ### Response #### Success Response (200) - **result** (List) - A list of decoded Message objects. ``` -------------------------------- ### Connect to Realtime websocket Source: https://github.com/supabase-community/supabase-kt/wiki/Realtime/Realtime Establish a connection to the Realtime websocket server. ```kotlin client.realtime.connect() ``` -------------------------------- ### Configure Storage Upload Options Source: https://github.com/supabase-community/supabase-kt/blob/master/MIGRATION.md Use the options DSL to configure upload behavior like upserting, content type, and HTTP request configurations. Content type will be inferred if null. ```kotlin supabase.storage.from("test").upload("test.txt", "Hello World!".encodeToByteArray()) { contentType = ContentType.Text.Plain upsert = true } ``` -------------------------------- ### Register New Users Source: https://github.com/supabase-community/supabase-kt/wiki/GoTrue/Admin API Creates new user accounts via email or phone number. ```kotlin client.gotrue.admin.createUserWithEmail { email = "example@foo.bar" password = "12345678" autoConfirm = true //automatically confirm this email address } client.gotrue.admin.createUserWithPhone { phoneNumber = "123456789" password = "12345678" } ``` -------------------------------- ### Create standalone Realtime module Source: https://github.com/supabase-community/supabase-kt/wiki/Realtime/Realtime Initialize a standalone Realtime module if only the Realtime functionality is required. ```kotlin val realtime = standaloneSupabaseModule(Realtime, url = "wss://your.realtime.url.com", apiKey = "your-api-key") ``` -------------------------------- ### Create Standalone Storage Module Source: https://github.com/supabase-community/supabase-kt/wiki/Storage/Storage Instantiate a standalone Storage module if you only require this specific Supabase module. Provide your storage URL and API key. ```kotlin val storage = standaloneSupabaseModule(Storage, url = "https://your.storage.url.com", apiKey = "your-api-key") ``` -------------------------------- ### Create standalone Postgrest module Source: https://github.com/supabase-community/supabase-kt/wiki/Postgrest/Postgrest Initialize a standalone Postgrest module if only this specific Supabase functionality is required. ```kotlin val postgrest = standaloneSupabaseModule(Postgrest, url = "https://your.postgrest.url.com", apiKey = "your-api-key") ``` -------------------------------- ### Add Supabase-kt and Ktor Dependencies (Groovy) Source: https://github.com/supabase-community/supabase-kt/wiki/Installation Include the core supabase-kt module and a Ktor client engine using Gradle's Groovy syntax. Replace VERSION and KTOR_VERSION with actual version numbers. ```groovy dependencies { implementation 'io.github.jan-tennert.supabase:[module e.g. functions-kt or gotrue-kt]:VERSION' //add ktor client engine (if you don't already have one, see https://ktor.io/docs/http-client-engines.html for all engines) //e.g. the CIO engine implementation 'io.ktor:ktor-client-cio:KTOR_VERSION' } ``` -------------------------------- ### Create and Verify MFA Challenge Simultaneously Source: https://github.com/supabase-community/supabase-kt/wiki/GoTrue/MFA A convenience method to create an MFA challenge and verify it in a single step. Use this when you want to immediately confirm the user's MFA code without a separate challenge creation step. ```kotlin client.gotrue.mfa.createChallengeAndVerify(factor.id, "123456") ``` -------------------------------- ### Create or Continue Resumable Upload Source: https://github.com/supabase-community/supabase-kt/wiki/Storage/Resumable uploads Initializes a resumable upload session for different platforms including JVM, Android, and others. ```kotlin //JVM/Android val upload = client.storage["test"].resumable.createOrContinueUpload( file = File("video.mp4"), path = "video.mp4", ) //Android val upload = client.storage["test"].resumable.createOrContinueUpload( uri = Uri.parse("content://media/external/video/media/1"), path = "video.mp4", ) //Other platforms (you might create extension functions yourself client.storage["test"].resumable.createOrContinueUpload(data = bytearray, source = "source for resuming after restart", path = "path") ``` -------------------------------- ### Download a file as a Flow with progress updates Source: https://github.com/supabase-community/supabase-kt/wiki/Storage/Managing files Downloads a file and provides download progress updates through a Flow. Collect the flow to monitor the download status, including received bytes and total size. ```kotlin client.storage["icons"].downloadPublicAsFlow("1654898740006.jpg").collect { when(status) { is DownloadStatus.Progress -> println("Percent done: ${status.received.toDouble() / status.total.toDouble() * 100}") is DownloadStatus.Success -> println("Done: ${status.data.size} bytes") } } ``` -------------------------------- ### Sign in with SSO Domain (New Auth API) Source: https://github.com/supabase-community/supabase-kt/blob/master/MIGRATION.md Use the new `auth.signInWith(SSO)` method to sign in using a specific SSO domain. This replaces the older `gotrue.loginWith(SSO.withDomain(...))`. ```kotlin supabase.auth.signInWith(SSO) { domain = "domain" } ``` -------------------------------- ### Configure Compose-ImageLoader with Supabase Fetcher and Keyer Source: https://github.com/supabase-community/supabase-kt/blob/master/plugins/ImageLoaderIntegration/README.md Configure your ImageLoader instance to use Supabase's fetcher and keyer for downloading and caching images from Supabase Storage. ```kotlin ImageLoader { //... components { add(keyer = supabaseClient.imageLoader) add(fetcherFactory = supabaseClient.imageLoader) } //... } ``` -------------------------------- ### Retrieve All Users Source: https://github.com/supabase-community/supabase-kt/wiki/GoTrue/Admin API Fetches a list of all users from the authentication database. ```kotlin val users: List = client.gotrue.admin.retrieveUsers() ``` -------------------------------- ### Run JS Canvas Build Source: https://github.com/supabase-community/supabase-kt/blob/master/sample/chat-demo-mpp/README.md Command to run the chat app on JS Canvas for web deployment. ```bash ./gradlew :sample:chat-demo-mpp:web:jsBrowserDevelopmentRun ``` -------------------------------- ### Login with Email and Password (AAL1) Source: https://github.com/supabase-community/supabase-kt/wiki/GoTrue/MFA Standard login flow using email and password, which results in an Authentication Assurance Level 1 (AAL1) session. This is the initial step before potentially upgrading to AAL2 with MFA. ```kotlin supabaseClient.gotrue.loginWith(Email) { email = "example@email.com" password = "12345" } ``` -------------------------------- ### Generate Auth Links Source: https://github.com/supabase-community/supabase-kt/wiki/GoTrue/Admin API Creates magic links or signup links for authentication flows. ```kotlin val (link, user) = client.gotrue.admin.generateLinkFor(LinkType.MagicLink) { email = "example@foo.bar" } val (link, user) = client.gotrue.admin.generateLinkFor(LinkType.Signup) { email = "example@foo.bar" password = "12345678" } ``` -------------------------------- ### Sign in with SSO Provider (New Auth API) Source: https://github.com/supabase-community/supabase-kt/blob/master/MIGRATION.md Use the new `auth.signInWith(SSO)` method to sign in using a specific SSO provider. This replaces the older `gotrue.loginWith(SSO.withProvider(...))`. ```kotlin supabase.auth.signInWith(SSO) { providerId = "providerId" } ``` -------------------------------- ### Configure local Maven repository in build.gradle.kts Source: https://github.com/supabase-community/supabase-kt/blob/master/CONTRIBUTING.md Add this to your project's build.gradle.kts to enable the local Maven repository. ```kotlin repositories { mavenLocal() } ``` -------------------------------- ### Add Supabase-kt and Ktor Dependencies (Kotlin DSL) Source: https://github.com/supabase-community/supabase-kt/wiki/Installation Configure your project to use supabase-kt modules and a Ktor client engine with Gradle's Kotlin DSL. Ensure you replace VERSION and KTOR_VERSION with the correct version identifiers. ```kotlin dependencies { implementation("io.github.jan-tennert.supabase:[module e.g. functions-kt or gotrue-kt]:VERSION") //add ktor client engine (if you don't already have one, see https://ktor.io/docs/http-client-engines.html for all engines) //e.g. the CIO engine implementation("io.ktor:ktor-client-cio:KTOR_VERSION") } ``` -------------------------------- ### Login with SSO Provider (Old GoTrue API) Source: https://github.com/supabase-community/supabase-kt/blob/master/MIGRATION.md This is the old method for logging in with a specific SSO provider using the `gotrue-kt` module. ```kotlin supabase.gotrue.loginWith(SSO.withProvider("provider")) ``` -------------------------------- ### Upload a file as a Flow with progress updates Source: https://github.com/supabase-community/supabase-kt/wiki/Storage/Managing files Uploads a file and provides upload progress updates through a Flow. Collect the flow to monitor the upload status, including progress, success, or failure. ```kotlin client.storage["icons"].uploadAsFlow("test.png", File("test.png").readBytes()).collect { when(it) { is UploadStatus.Progress -> println("Percent done: ${it.sent.toDouble() / it.total.toDouble() * 100}") is UploadStatus.Success -> println("Done: ${it.key}") } } ``` -------------------------------- ### Login with SSO Domain (Old GoTrue API) Source: https://github.com/supabase-community/supabase-kt/blob/master/MIGRATION.md This is the old method for logging in with a specific SSO domain using the `gotrue-kt` module. ```kotlin supabase.gotrue.loginWith(SSO.withDomain("domain")) ``` -------------------------------- ### Retrieve a storage bucket Source: https://github.com/supabase-community/supabase-kt/wiki/Storage/Managing Buckets Fetches an existing bucket instance by its unique identifier. ```kotlin val bucket = client.getBucket(id = "id") ``` -------------------------------- ### Advanced Postgrest Query Options Source: https://github.com/supabase-community/supabase-kt/blob/master/MIGRATION.md Demonstrates various advanced query options available in the Postgrest builder, including retrieving a single object, setting counts, limits, ranges, and specifying return formats like CSV or GeoJSON. ```kotlin val result = supabase.postgrest["messages"].select { single() //receive an object rather than an array count(Count.EXACT) //receive amount of database entries limit(10) //limit amount of results range(2, 3) //change range of results select() //return the data when updating/deleting/upserting (same as settings 'returning' to REPRESENTATION before) csv() //Receive the data as csv geojson() //Receive the data as geojson explain(/* */) //Debug queries filter { eq("id", 1) } } ``` -------------------------------- ### Publish changes to local Maven repository Source: https://github.com/supabase-community/supabase-kt/blob/master/CONTRIBUTING.md Use this command in the project root to publish local changes for testing. ```shell ./gradlew -DLibrariesOnly=true -DDisableSigning=true -DSupabaseVersion="customVersion" publishToMavenLocal ``` -------------------------------- ### GoTrue Admin API - Create User Source: https://github.com/supabase-community/supabase-kt/wiki/GoTrue/Admin API Creates a new user with either email and password or phone number and password. Requires the service role secret. ```APIDOC ## POST /admin/users ### Description Registers new users. ### Method POST ### Endpoint /admin/users ### Parameters #### Query Parameters - **service_role_key** (string) - Required - The service role secret for admin access. #### Request Body - **email** (string) - Optional - The email address of the new user. - **phone_number** (string) - Optional - The phone number of the new user. - **password** (string) - Required - The password for the new user. - **auto_confirm** (boolean) - Optional - If true, the user's email will be automatically confirmed. ### Request Example ```kotlin // Create user with email client.gotrue.admin.createUserWithEmail { email = "example@foo.bar" password = "12345678" autoConfirm = true } // Create user with phone number client.gotrue.admin.createUserWithPhone { phoneNumber = "123456789" password = "12345678" } ``` ### Response #### Success Response (201) - **id** (string) - The unique identifier for the newly created user. - **email** (string) - The email address of the user. - **phone** (string) - The phone number of the user. - **created_at** (string) - The timestamp when the user was created. #### Response Example ```json { "id": "f1e2d3c4-b5a6-7890-1234-567890fedcba", "email": "example@foo.bar", "phone": null, "created_at": "2023-01-02T11:00:00Z" } ``` ``` -------------------------------- ### Login with Email and Password in Supabase Kotlin Source: https://github.com/supabase-community/supabase-kt/wiki/GoTrue/Login Use `loginWith(Email)` to authenticate users with their email and password. Ensure you have a Supabase client instance configured. ```kotlin supabaseClient.gotrue.loginWith(Email) { email = "example@email.com" password = "12345" } //with phone: supabaseClient.gotrue.loginWith(Phone) { phone = "123456789" password = "12345" } println(supabaseClient.gotrue.currentAccessTokenOrNull()) ``` -------------------------------- ### Configure SessionManager for Desktop Source: https://github.com/supabase-community/supabase-kt/wiki/GoTrue/Session Saving Sets a custom PreferencesSettings instance for the GoTrue module on desktop platforms. ```kotlin install(GoTrue) { sessionManager = SettingsSessionManager(PreferencesSettings(Preferences.userRoot().node("custom_name"))) } ``` -------------------------------- ### Create Standalone Functions Module Source: https://github.com/supabase-community/supabase-kt/wiki/Functions/Functions Initialize a standalone module if only the Functions functionality is required. ```kotlin val functions = standaloneSupabaseModule(Functions, url = "https://your.functions.url.com", apiKey = "your-api-key") ``` -------------------------------- ### Add Postgrest-kt Dependency Source: https://github.com/supabase-community/supabase-kt/blob/master/Postgrest/README.md Include the Postgrest-kt library in your project's dependencies to use the Postgrest client. ```kotlin dependencies { implementation("io.github.jan-tennert.supabase:postgrest-kt:VERSION") } ``` -------------------------------- ### Access Realtime plugin Source: https://github.com/supabase-community/supabase-kt/wiki/Realtime/Realtime Access the Realtime plugin instance from the Supabase client. ```kotlin client.realtime ``` -------------------------------- ### Download a file from Supabase Storage Source: https://github.com/supabase-community/supabase-kt/wiki/Storage/Managing files Downloads a file from a specified bucket. Use `downloadPublic` for public buckets and `downloadAuthenticated` for private buckets. Transformations like quality and size can be applied. ```kotlin val bytes = bucket.downloadPublic("landscape.png") //download public for public buckets and download authenticated for private buckets ``` ```kotlin bucket.downloadTo("landscape.png", File("landscape.png")) ``` ```kotlin //transform the image when downloading val bytes = bucket.downloadPublic("landscape.png") { quality = 80 size(700, 400) fill() } ``` -------------------------------- ### Create MFA Challenge for Verification Source: https://github.com/supabase-community/supabase-kt/wiki/GoTrue/MFA Initiate the MFA verification process by creating a challenge for a specific factor. This step is typically followed by the user entering a code from their authenticator app. ```kotlin val challenge = client.gotrue.mfa.createChallenge(factor.id) ``` -------------------------------- ### Create standalone GoTrue module Source: https://github.com/supabase-community/supabase-kt/wiki/GoTrue/GoTrue Initialize a standalone GoTrue module if only the authentication functionality is required. ```kotlin val gotrue = standaloneSupabaseModule(GoTrue, url = "https://your.gotrue.url.com", apiKey = "your-api-key") ``` -------------------------------- ### Use Supabase BOM for Version Management Source: https://github.com/supabase-community/supabase-kt/blob/master/README.md When using multiple Supabase modules, the Bill of Materials (BOM) dependency ensures all modules use compatible versions. Replace 'VERSION' with the library version. ```kotlin implementation(platform("io.github.jan-tennert.supabase:bom:VERSION")) implementation("io.github.jan-tennert.supabase:[module]") ``` -------------------------------- ### Implement a Custom Supabase Plugin Source: https://github.com/supabase-community/supabase-kt/wiki/Creating-Plugins Define a plugin class by implementing SupabasePlugin and providing a companion object that implements SupabasePluginProvider. ```kotlin class MyPlugin(private val config: MyPlugin.Config): SupabasePlugin { fun doSomethingCool() { println("something cool") } data class Config(var someSetting: Boolean = false) companion object : SupabasePluginProvider { override val key = "myplugin" //this key is used to identify the plugin when retrieving it override fun createConfig(init: Config.() -> Unit): Config { //used to create the configuration object for the plugin return Config().apply(init) } override fun setup(builder: SupabaseClientBuilder, config: Config) { //modify the supabase client builder } override fun create(supabaseClient: SupabaseClient, config: Config): MyPlugin { //modify the supabase client and return the final plugin instance return MyPlugin(config) } } } ``` -------------------------------- ### Listen to Upload Progress Source: https://github.com/supabase-community/supabase-kt/wiki/Storage/Resumable uploads Collects state updates from the upload process to monitor progress and status. ```kotlin upload.stateFlow.collect { println(it.paused) println(it.progress) println(it.status) } ``` -------------------------------- ### Create Plugin Extension Property Source: https://github.com/supabase-community/supabase-kt/wiki/Creating-Plugins Define an extension property on SupabaseClient to allow easy access to the custom plugin instance. ```kotlin val SupabaseClient.myplugin get() = pluginManager.getPlugin(MyPlugin) ``` -------------------------------- ### Verify OTP tokens Source: https://github.com/supabase-community/supabase-kt/wiki/GoTrue/GoTrue Verify tokens for signup, invite, or recovery flows using email or phone methods. ```kotlin supabaseClient.gotrue.verifyEmailOtp(OtpType.Email.SIGNUP, token = "token", email = "example@email.com") supabaseClient.gotrue.verifyPhoneOtp(OtpType.Phone.SMS, token = "token", phoneNumber = "123456") ``` -------------------------------- ### Add Supabase Module Dependency Source: https://github.com/supabase-community/supabase-kt/blob/master/README.md Use this to add a specific Supabase module to your project. Replace '[module]' with the desired module (e.g., 'auth-kt', 'postgrest-kt') and 'VERSION' with the library version. ```kotlin dependencies { implementation("io.github.jan-tennert.supabase:[module]:VERSION") } ``` -------------------------------- ### Access Functions Plugin Source: https://github.com/supabase-community/supabase-kt/wiki/Functions/Functions Access the plugin instance from the client. ```kotlin client.functions ``` -------------------------------- ### Add Ktor Client Engine Dependency Source: https://github.com/supabase-community/supabase-kt/blob/master/README.md Include a Ktor client engine dependency for your target platform. Replace '[engine]' with the engine name (e.g., 'cio', 'js', 'darwin') and 'VERSION' with the Ktor version. ```kotlin implementation("io.ktor:ktor-client-[engine]:VERSION") ``` -------------------------------- ### Select Data with Filters in Postgrest Source: https://github.com/supabase-community/supabase-kt/blob/master/MIGRATION.md Use the new builder syntax for selecting data with filters. The `filter` block is now required for applying conditions like `eq`. ```kotlin supabase.postgrest.from("countries").select { count(Count.EXACT) filter { eq("id", 1) } } ``` -------------------------------- ### Send OTP to phone or email Source: https://github.com/supabase-community/supabase-kt/wiki/GoTrue/GoTrue Trigger an OTP request for authentication via email or phone. ```kotlin supabaseClient.gotrue.sendOtpTo(Email) { email = "example@email.com" password = "12345" } ``` -------------------------------- ### Enable Debug Logs in Supabase Client Source: https://github.com/supabase-community/supabase-kt/blob/master/TROUBLESHOOTING.md To view debug logs, set the `defaultLogLevel` to `LogLevel.DEBUG` during Supabase client initialization. ```kotlin val supabase = createSupabaseClient(supabaseUrl, supabaseKey) { defaultLogLevel = LogLevel.DEBUG } ``` -------------------------------- ### Import JWT token Source: https://github.com/supabase-community/supabase-kt/wiki/GoTrue/GoTrue Manually import an authentication token. Note that auto-refresh is not available for imported tokens. ```kotlin supabaseClient.gotrue.importAuthToken("your_token") ``` -------------------------------- ### Send OTP via Email (Old GoTrue API) Source: https://github.com/supabase-community/supabase-kt/blob/master/MIGRATION.md This is the old method for sending a One-Time Password to an email address using the `gotrue-kt` module. ```kotlin supabase.gotrue.sendOtpTo(Email) { email = "example@email.com" } ``` -------------------------------- ### Send OTP via Email (New Auth API) Source: https://github.com/supabase-community/supabase-kt/blob/master/MIGRATION.md Use the new `auth.signInWith(OTP)` method to send a One-Time Password to an email address. This replaces the older `gotrue.sendOtpTo` method. ```kotlin supabase.auth.signInWith(OTP) { email = "example@email.com" } ``` -------------------------------- ### Add Supabase-kt imageloader-integration Dependency Source: https://github.com/supabase-community/supabase-kt/blob/master/plugins/ImageLoaderIntegration/README.md Add the imageloader-integration dependency to your project's build.gradle file. Replace VERSION with the latest version number. ```kotlin dependencies { implementation("io.github.jan-tennert.supabase:imageloader-integration:VERSION") } ``` -------------------------------- ### Add Supabase-kt Storage Dependency Source: https://github.com/supabase-community/supabase-kt/blob/master/Storage/README.md Include the storage-kt dependency in your project's build.gradle file. Replace VERSION with the latest release number. ```kotlin dependencies { implementation("io.github.jan-tennert.supabase:storage-kt:VERSION") } ``` -------------------------------- ### Embed and Sign Apple Framework for Xcode Source: https://github.com/supabase-community/supabase-kt/blob/master/sample/chat-demo-mpp/README.md Run script phase for embedding and signing the common framework for Xcode iOS development. Ensure this script is placed above 'Compile Sources' in Xcode's 'Build phases'. ```cmd cd "$SRCROOT/.." ./gradlew :sample:chat-demo-mpp:common:embedAndSignAppleFrameworkForXcode ``` -------------------------------- ### Configure Postgrest Upsert Options Source: https://github.com/supabase-community/supabase-kt/blob/master/MIGRATION.md Move optional parameters for upsert operations to the request DSL. Set defaultToNull and ignoreDuplicates as needed. ```kotlin supabase.from("table").upsert(myValue) { defaultToNull = false ignoreDuplicates = false } ``` -------------------------------- ### GoTrue Admin API - Generate Link Source: https://github.com/supabase-community/supabase-kt/wiki/GoTrue/Admin API Generates a magic link or signup link for a user. Requires the service role secret. ```APIDOC ## POST /admin/auth/generate-link ### Description Generates a link for authentication purposes (e.g., MagicLink, Signup). ### Method POST ### Endpoint /admin/auth/generate-link ### Parameters #### Query Parameters - **service_role_key** (string) - Required - The service role secret for admin access. #### Request Body - **type** (string) - Required - The type of link to generate (e.g., "magiclink", "signup"). - **email** (string) - Required - The email address of the user. - **password** (string) - Optional - The password for the user, required for signup links. ### Request Example ```kotlin // Generate MagicLink val (link, user) = client.gotrue.admin.generateLinkFor(LinkType.MagicLink) { email = "example@foo.bar" } // Generate Signup Link val (link, user) = client.gotrue.admin.generateLinkFor(LinkType.Signup) { email = "example@foo.bar" password = "12345678" } ``` ### Response #### Success Response (200) - **link** (string) - The generated authentication link. - **user** (object) - The user object associated with the link. - **id** (string) - The unique identifier for the user. - **email** (string) - The email address of the user. #### Response Example ```json { "link": "https://your-app.supabase.co/auth/v1/verify?token=...", "user": { "id": "g1h2i3j4-k5l6-7890-1234-567890klmno", "email": "example@foo.bar" } } ``` ``` -------------------------------- ### Verify MFA Challenge Source: https://github.com/supabase-community/supabase-kt/wiki/GoTrue/MFA Verify a previously created MFA challenge using the factor ID, challenge ID, and the code provided by the user. This confirms the user's identity for MFA. ```kotlin client.gotrue.mfa.verifyChallenge(factor.id, challenge.id, "123456") //123456 is the code the user entered ``` -------------------------------- ### Configure Resumable Cache Source: https://github.com/supabase-community/supabase-kt/wiki/Storage/Resumable uploads Customizes the storage cache strategy for upload URLs. ```kotlin install(Storage) { resumable { cache = ResumableCache.Memory() } } ``` ```kotlin install(Storage) { resumable { cache = ResumableCache.Disk() } ``` -------------------------------- ### Upload a file to Supabase Storage Source: https://github.com/supabase-community/supabase-kt/wiki/Storage/Managing files Uploads a file to a specified bucket. Supports uploading from bytes or a File object. ```kotlin val bucket = client.storage["images"] bucket.upload("landscape.png", bytes) ``` ```kotlin //upload a file (jvm) bucket.upload("landscape.png", File("landscape.png")) ``` -------------------------------- ### Add Supabase-kt Dependency Source: https://github.com/supabase-community/supabase-kt/blob/master/Supabase/README.md Include this dependency in your module's build.gradle file to use the main Supabase-kt library. Replace VERSION with the latest release number. ```kotlin dependencies { implementation("io.github.jan-tennert.supabase:supabase-kt:VERSION") } ``` -------------------------------- ### Storage API Source: https://github.com/supabase-community/supabase-kt/wiki/_Sidebar Endpoints for managing storage buckets and file operations. ```APIDOC ## POST /storage/v1/bucket ### Description Creates a new storage bucket. ### Method POST ### Endpoint /storage/v1/bucket ## POST /storage/v1/object/{bucket}/{path} ### Description Uploads a file to a specific path within a bucket. ### Method POST ### Endpoint /storage/v1/object/{bucket}/{path} ``` -------------------------------- ### Send recovery email Source: https://github.com/supabase-community/supabase-kt/wiki/GoTrue/GoTrue Initiate the password recovery flow by sending an email to the user. ```kotlin supabaseClient.gotrue.sendRecoveryEmail("example@email.com") ``` -------------------------------- ### Listen to Session Changes in Supabase Kotlin Source: https://github.com/supabase-community/supabase-kt/wiki/GoTrue/Login Monitor authentication state changes using the `sessionStatus` flow. This flow emits updates for authentication status, network errors, and loading states. ```kotlin // sessionStatus can be of type // - SessionStatus.NotAuthenticated // - SessionStatus.Authenticated(session) // - SessionStatus.NetworkError // - SessionStatus.LoadingFromStorage ``` -------------------------------- ### Retrieve All MFA Factors for Current User Source: https://github.com/supabase-community/supabase-kt/wiki/GoTrue/MFA Fetch all MFA factors associated with the current user from the server and filter them to include only those that are verified. This provides a comprehensive list of active MFA factors. ```kotlin val factors = client.gotrue.mfa.retrieveFactorsForCurrentUser().filter(UserMfaFactor::isVerified) ``` -------------------------------- ### Enable Kotlin Serialization Plugin Source: https://github.com/supabase-community/supabase-kt/wiki/Installation Apply the Kotlin serialization plugin in your Gradle build script to enable serialization for your data classes. Replace KOTLIN_VERSION with the appropriate Kotlin version. ```kotlin plugins { id("org.jetbrains.kotlin.plugin.serialization") version KOTLIN_VERSION } ``` -------------------------------- ### Send OTP via Phone (New Auth API) Source: https://github.com/supabase-community/supabase-kt/blob/master/MIGRATION.md Use the new `auth.signInWith(OTP)` method to send a One-Time Password to a phone number. This replaces the older `gotrue.sendOtpTo` method. ```kotlin supabase.auth.signInWith(OTP) { phone = "+123456789" } ``` -------------------------------- ### Execute database functions with Supabase Kotlin Source: https://github.com/supabase-community/supabase-kt/wiki/Postgrest/Execute Database functions Use the rpc method to trigger database functions. Parameters can be passed as a map, and filters can be applied using a trailing lambda. ```kotlin client.postgrest.rpc("do_something") //with parameters and filter client.postgrest.rpc("do_something", mapOf("param1" to "value1")) { eq("id", 1) } ``` -------------------------------- ### Send OTP via Phone (Old GoTrue API) Source: https://github.com/supabase-community/supabase-kt/blob/master/MIGRATION.md This is the old method for sending a One-Time Password to a phone number using the `gotrue-kt` module. ```kotlin supabase.gotrue.sendOtpTo(Phone) { phoneNumber = "+123456789" } ``` -------------------------------- ### Retrieve Verified MFA Factors for Current User Source: https://github.com/supabase-community/supabase-kt/wiki/GoTrue/MFA Access the list of MFA factors that have already been verified and are associated with the current user's session. These are stored locally within the session data. ```kotlin val verifiedFactors = client.gotrue.mfa.verifiedFactors ``` -------------------------------- ### Pause and Resume Upload Source: https://github.com/supabase-community/supabase-kt/wiki/Storage/Resumable uploads Pauses an active upload and resumes it after a delay. ```kotlin upload.pause() delay(2000) upload.startOrResumeUploading() ``` -------------------------------- ### OAuth Login for Android Apps with Supabase Kotlin Source: https://github.com/supabase-community/supabase-kt/wiki/GoTrue/Login Configure OAuth login for Android applications by setting up the deep link scheme and host in the Supabase deeplink plugin and Android manifest. Handle deep links using `supabaseClient.handleDeeplinks(intent)` in your `MainActivity`. ```kotlin class MainActivity : AppCompatActivity() { val supabaseClient = createSupabaseClient(supabaseUrl = "...", supabaseKey = "...") { supabaseUrl = "your supabase url" supabaseKey = "your supabase key" install(GoTrue) { scheme = "supacompose" host = "login" } } override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) supabaseClient.handleDeeplinks(intent) //without this no deeplinks will get recognized //somewhere in an onClick callback: supabaseClient.loginWith(Google) //this should go in a viewmodel } } ``` -------------------------------- ### Broadcast Messages to Clients Source: https://github.com/supabase-community/supabase-kt/wiki/Realtime/Broadcast API Send data to other clients by specifying the event name and the payload. ```kotlin channel.broadcast("position", Position(20, 30)) //broadcast your position to other clients (in the event "position") ``` -------------------------------- ### Display Image from Supabase Storage Source: https://github.com/supabase-community/supabase-kt/blob/master/plugins/ImageLoaderIntegration/README.md Use the AutoSizeImage composable with an ImageRequest pointing to your Supabase Storage item. Use authenticatedStorageItem for private buckets or publicStorageItem for public buckets. ```kotlin AutoSizeImage( request = remember { ImageRequest(authenticatedStorageItem("icons", "user.png")) }, //or use publicStorageItem("icons", "user.png") for public buckets contentDescription = null ) ``` -------------------------------- ### Add Jackson Serializer to Project Source: https://github.com/supabase-community/supabase-kt/blob/master/serializers/Jackson/README.md Include the Jackson Serializer module in your project's dependencies to enable JSON serialization and deserialization for Supabase interactions. ```kotlin dependencies { implementation("io.github.jan-tennert.supabase:serializer-jackson:VERSION") } ``` -------------------------------- ### Listen for Presence Updates Source: https://github.com/supabase-community/supabase-kt/wiki/Realtime/Presence API Obtain a Flow of PresenceAction objects from the channel to receive presence updates. Decode join and leave events into your PresenceData class to manage online users. ```kotlin val presenceFlow: Flow = channel.presenceFlow() presenceFlow.collect { otherUsers += it.decodeJoinsAs() otherUsers -= it.decodeLeavesAs() } ``` -------------------------------- ### Listen for Broadcast Messages Source: https://github.com/supabase-community/supabase-kt/wiki/Realtime/Broadcast API Receive broadcast messages as a Flow by specifying the event name. ```kotlin val broadcastFlow: Flow = channel.broadcastFlow("position") broadcastFlow.collect { println(it) } ``` -------------------------------- ### Add Functions-kt Dependency Source: https://github.com/supabase-community/supabase-kt/blob/master/Functions/README.md Add the Functions-kt dependency to your project's build.gradle file. Replace VERSION with the latest release version. ```kotlin dependencies { implementation("io.github.jan-tennert.supabase:functions-kt:VERSION") } ``` -------------------------------- ### Access GoTrue plugin Source: https://github.com/supabase-community/supabase-kt/wiki/GoTrue/GoTrue Access the GoTrue plugin instance from the Supabase client. ```kotlin client.gotrue ``` -------------------------------- ### Enroll a New MFA Factor (TOTP) Source: https://github.com/supabase-community/supabase-kt/wiki/GoTrue/MFA Enroll a new TOTP factor for a user. Currently, TOTP is the only supported type. Requires a friendly name and issuer for the factor. ```kotlin val factor = client.gotrue.mfa.enroll(FactorType.TOTP, friendlyName = "Name", issuer = "Issuer") //no other type supported currently ``` -------------------------------- ### Build Reusable Edge Function Source: https://github.com/supabase-community/supabase-kt/wiki/Functions/Functions Create an EdgeFunction instance to execute the same function multiple times with different inputs. ```kotlin @Serializable data class SomeData(val name: String) val testFunction: EdgeFunction = client.functions.buildEdgeFunction( function = "test", headers = Headers.build { append(HttpHeaders.ContentType, "application/json") } ) val response: HttpResponse = testFunction() //with body val response: HttpResponse = testFunction(SomeData("Name")) ``` -------------------------------- ### Continue Cached Uploads Source: https://github.com/supabase-community/supabase-kt/wiki/Storage/Resumable uploads Resumes previously interrupted uploads after an application restart or crash. ```kotlin //JVM/Android client.storage["test"].resumable.continuePreviousFileUploads().forEach { upload -> scope.launch { val upload = upload.await() upload.startOrResumeUploading() } } //Other platforms (you might want to create your own extension function) client.storage["test"].resumable.continuePreviousUploads { source -> //create bytereadchannel from source }.forEach { upload -> scope.launch { val upload = upload.await() upload.startOrResumeUploading() } } ``` -------------------------------- ### Add dependency to build.gradle.kts Source: https://github.com/supabase-community/supabase-kt/blob/master/CONTRIBUTING.md Include the specific module dependency in your project using the custom version. ```kotlin implementation("io.github.jan-tennert.supabase:[module]:customVersion") ``` -------------------------------- ### Update Data with Returning Representation in Postgrest Source: https://github.com/supabase-community/supabase-kt/blob/master/MIGRATION.md When updating data, use the `select()` method within the builder to specify that you want the updated data returned. Without this, the default is `MINIMAL`. ```kotlin supabase.postgrest.from("countries").update(country) { select() //Without this the "returning" parameter is `MINIMAL`, meaning you will not receive the data. filter { eq("id", 1) } } ``` -------------------------------- ### Select Data with Filters Source: https://github.com/supabase-community/supabase-kt/wiki/Make-Database-Calls Select data from the 'messages' table using various filter conditions. Supports property references or direct string column names. Combine filters using 'and' and 'or'. ```kotlin val result = client.postgrest["messages"] .select { //you can use that syntax Message::authorId eq "someid" Message::text neq "This is a text!" Message::channelId isIn listOf("test", "test2") //or this. But they are the same eq("author_id", "someid") neq("text", "This is a text!") isIn("channel_id", listOf("test", "test2")) //use and + or to combine multiple filters or { eq("author_id", "someid") and { eq("author_id", "someid") neq("text", "This is a text!") } } } println(result.decodeList()) ``` -------------------------------- ### Insert Data Source: https://github.com/supabase-community/supabase-kt/wiki/Make-Database-Calls Insert a new message into the 'messages' table. Pass an instance of the Message data class to the insert function. ```kotlin client.postgrest["messages"] .insert(Message("This is a text!", "someid", 1)) ``` -------------------------------- ### Register Custom Class Serializer for Postgrest Source: https://github.com/supabase-community/supabase-kt/blob/master/TROUBLESHOOTING.md When using custom classes as parameters in Postgrest requests, register a serializer for the class. Ensure the class is annotated with `@Serializable`. ```kotlin @Serializable data class YourClass( val id: String, val name: String ) ``` -------------------------------- ### Define Presence Data Class Source: https://github.com/supabase-community/supabase-kt/wiki/Realtime/Presence API Define a data class for presence information. Ensure it is annotated with @Serializable and that the serialization plugin is added to your Gradle build. ```kotlin @Serializable data class PresenceData(val userId: Int, val username: String) ```