A Swift client for Supabase

Overview

supabase-swift

Swift Client library to interact with Supabase.

Sponsors

We are building the features of Firebase using enterprise-grade, open source products. We support existing communities wherever possible, and if the products don’t exist we build them and open source them ourselves. Thanks to these sponsors who are making the OSS ecosystem better for everyone.

New Sponsor

Comments
  • Realtime subscriptions don't work

    Realtime subscriptions don't work

    Socket is connected, channel is seemingly subscribed (it fires on "receive 'ok'")

    It never fires on ".all" or any other events

    Only when I unsubscribe "onClose" actually fires ("onError" never fires)

    Replication is enabled on all tables, it doesn't work even on non-RLS tables

    In API and Postgres logs I could only see "websocket" connections, didn't see any "subscription" logs if there are supposed to be any

    @grsouza please help

    I'm setting it up like Realtime Swift docs say

    opened by ooolzhas 7
  • Clarification on signed in row level security access via jwt

    Clarification on signed in row level security access via jwt

    Improve documentation

    let client = SupabaseClient(supabaseURL: SUPABASE_URL, supabaseKey: ANON_KEY)

    Describe the problem

    how can a signed in user access database with row level security? is there a way to switch in the jwt once we have it - eg. client.updateJWT( supabaseKey: authorisedJWT);

    I'm working on a sign in with apple / nodejs - native login flow - but once I have the jwt - how can I then proceed to use it.... https://github.com/johndpope/Sign-in-with-Apple-for-supabase

    documentation 
    opened by johndpope 6
  • [tvOS] Allow setting auth tokens manually

    [tvOS] Allow setting auth tokens manually

    We are developing a digital signage app for Apple TV (tvOS) and are considering to use Supabase as our backend service. While creating a proof of concept I stumbled upon a problem with authenticating. Since there is no web browser on tvOS the traditional auth flow won't work.

    Instead the user needs to sign in on another device and we need to set auth tokens manually on the SupabaseClient instance in our tvOS app. E.g. there might be a companion sign-in app on iOS that transfers auth tokens securely over to the tvOS app.
    But as of now there is no way to set auth tokens manually on the client itself.

    In supabase-js we have a method called setAuth() that lets you override the access token. Since the app basically does not have any user interaction at all, we also need to set the refresh token in order to stay authenticated while the app shows its content.

    opened by florivdg 6
  • can't seem to fetch rows.

    can't seem to fetch rows.

    Bug report

    I have this a test org and it's returning results fine using python https://gist.github.com/johndpope/4bdf87792c034fadb157766c702253d0

    Describe the bug

    When running same query I get no results in swift version.

    Screenshot 2022-11-18 at 7 43 44 am
    
    result: Optional(PostgREST.PostgrestResponse<()>(underlyingResponse: Get.Response<()>(value: (), response: <NSHTTPURLResponse: 0x600001263020> { URL: https://qfwzdkpmyzajmmvupgzy.supabase.co/rest/v1/tweets?select=* } { Status Code: 200, Headers {
        "Access-Control-Allow-Origin" =     (
            "*"
        );
        "Alt-Svc" =     (
            "h3=\":443\"; ma=86400, h3-29=\":443\"; ma=86400"
        );
        "Content-Encoding" =     (
            br
        );
        "Content-Location" =     (
            "/tweets?select=%2A"
        );
        "Content-Type" =     (
            "application/json; charset=utf-8"
        );
        Date =     (
            "Thu, 17 Nov 2022 20:43:22 GMT"
        );
        Server =     (
            cloudflare
        );
        Vary =     (
            "Accept-Encoding"
        );
        Via =     (
            "kong/2.8.1"
        );
        "cf-cache-status" =     (
            DYNAMIC
        );
        "cf-ray" =     (
            "76bb4c4babd6a97a-SYD"
        );
        "content-profile" =     (
            public
        );
        "content-range" =     (
            "0-999/*"
        );
        "sb-gateway-version" =     (
            1
        );
        "x-kong-proxy-latency" =     (
            0
        );
        "x-kong-upstream-latency" =     (
            15
        );
    } }, data: 422860 bytes, task: LocalDataTask <47B6B060-DF8F-4921-AE38-CF831D362865>.<1>, metrics: Optional((Task Interval) <_NSConcreteDateInterval: 0x60000125f3e0> (Start Date) 2022-11-17 20:43:20 +0000 + (Duration) 2.450190 seconds = (End Date) 2022-11-17 20:43:22 +0000
    (Redirect Count) 0
    (Transaction Metrics) (Request) <NSMutableURLRequest: 0x60000101c320> { URL: https://qfwzdkpmyzajmmvupgzy.supabase.co/rest/v1/tweets?select=* }
    (Response) <NSHTTPURLResponse: 0x600001262240> { URL: https://qfwzdkpmyzajmmvupgzy.supabase.co/rest/v1/tweets?select=* } { Status Code: 200, Headers {
        "Access-Control-Allow-Origin" =     (
            "*"
        );
        "Alt-Svc" =     (
            "h3=\":443\"; ma=86400, h3-29=\":443\"; ma=86400"
        );
        "Content-Encoding" =     (
            br
        );
        "Content-Location" =     (
            "/tweets?select=%2A"
        );
        "Content-Type" =     (
            "application/json; charset=utf-8"
        );
        Date =     (
            "Thu, 17 Nov 2022 20:27:54 GMT"
        );
        Server =     (
            cloudflare
        );
        Vary =     (
            "Accept-Encoding"
        );
        Via =     (
            "kong/2.8.1"
        );
        "cf-cache-status" =     (
            DYNAMIC
        );
        "cf-ray" =     (
            "76bb35a7adf3a974-SYD"
        );
        "content-profile" =     (
            public
        );
        "content-range" =     (
            "0-999/*"
        );
        "sb-gateway-version" =     (
            1
        );
        "x-kong-proxy-latency" =     (
            1
        );
        "x-kong-upstream-latency" =     (
            15
        );
    } }
    (Fetch Start) 2022-11-17 20:43:20 +0000
    (Domain Lookup Start) (null)
    (Domain Lookup End) (null)
    (Connect Start) (null)
    (Secure Connection Start) (null)
    (Secure Connection End) (null)
    (Connect End) (null)
    (Request Start) 2022-11-17 20:43:20 +0000
    (Request End) 2022-11-17 20:43:20 +0000
    (Response Start) 2022-11-17 20:43:20 +0000
    (Response End) 2022-11-17 20:43:20 +0000
    (Protocol Name) (null)
    (Proxy Connection) NO
    (Reused Connection) NO
    (Fetch Type) Local Cache
    (Request Header Bytes) 0
    (Request Body Transfer Bytes) 0
    (Request Body Bytes) 0
    (Response Header Bytes) 0
    (Response Body Transfer Bytes) 0
    (Response Body Bytes) 0
    (Local Address) (null)
    (Local Port) (null)
    (Remote Address) (null)
    (Remote Port) (null)
    (TLS Protocol Version) 0x0000
    (TLS Cipher Suite) 0x0000
    (Cellular) NO
    (Expensive) NO
    (Constrained) NO
    (Multipath) NO
    
    (Request) <NSURLRequest: 0x60000101caf0> { URL: https://qfwzdkpmyzajmmvupgzy.supabase.co/rest/v1/tweets?select=* }
    (Response) <NSHTTPURLResponse: 0x60000124e260> { URL: https://qfwzdkpmyzajmmvupgzy.supabase.co/rest/v1/tweets?select=* } { Status Code: 200, Headers {
        "Access-Control-Allow-Origin" =     (
            "*"
        );
        "Alt-Svc" =     (
            "h3=\":443\"; ma=86400, h3-29=\":443\"; ma=86400"
        );
        "Content-Encoding" =     (
            br
        );
        "Content-Location" =     (
            "/tweets?select=%2A"
        );
        "Content-Type" =     (
            "application/json; charset=utf-8"
        );
        Date =     (
            "Thu, 17 Nov 2022 20:43:22 GMT"
        );
        Server =     (
            cloudflare
        );
        Vary =     (
            "Accept-Encoding"
        );
        Via =     (
            "kong/2.8.1"
        );
        "cf-cache-status" =     (
            DYNAMIC
        );
        "cf-ray" =     (
            "76bb4c4babd6a97a-SYD"
        );
        "content-profile" =     (
            public
        );
        "content-range" =     (
            "0-999/*"
        );
        "sb-gateway-version" =     (
            1
        );
        "x-kong-proxy-latency" =     (
            0
        );
        "x-kong-upstream-latency" =     (
            15
        );
    } }
    (Fetch Start) 2022-11-17 20:43:20 +0000
    (Domain Lookup Start) 2022-11-17 20:43:20 +0000
    (Domain Lookup End) 2022-11-17 20:43:20 +0000
    (Connect Start) 2022-11-17 20:43:20 +0000
    (Secure Connection Start) 2022-11-17 20:43:20 +0000
    (Secure Connection End) 2022-11-17 20:43:20 +0000
    (Connect End) 2022-11-17 20:43:20 +0000
    (Request Start) 2022-11-17 20:43:20 +0000
    (Request End) 2022-11-17 20:43:20 +0000
    (Response Start) 2022-11-17 20:43:22 +0000
    (Response End) 2022-11-17 20:43:22 +0000
    (Protocol Name) h3
    (Proxy Connection) NO
    (Reused Connection) NO
    (Fetch Type) Network Load
    (Request Header Bytes) 998
    (Request Body Transfer Bytes) 0
    (Request Body Bytes) 0
    (Response Header Bytes) 295
    (Response Body Transfer Bytes) 110951
    (Response Body Bytes) 422860
    (Local Address) 192.168.1.100
    (Local Port) 62732
    (Remote Address) 104.18.26.135
    (Remote Port) 443
    (TLS Protocol Version) 0x0304
    (TLS Cipher Suite) 0x1301
    (Cellular) NO
    (Expensive) NO
    (Constrained) NO
    (Multipath) NO
    
    )), count: nil))
    

    To Reproduce

    
        override func viewDidLoad() {
            super.viewDidLoad()
            setupDatabase()
        }
        
        func setupDatabase() {
            let SUPABASE_URL = URL(string:"https://qfwzdkpmyzajmmvupgzy.supabase.co")!
            let ANON_KEY = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6InFmd3pka3BteXpham1tdnVwZ3p5Iiwicm9sZSI6ImFub24iLCJpYXQiOjE2NjgxMzAzMjYsImV4cCI6MTk4MzcwNjMyNn0.kEweOMrRSJ0mtOIXnsRmbNxf4yqoZAZf398jlGgSxtQ"
            self.client = SupabaseClient(supabaseURL: SUPABASE_URL, supabaseKey: ANON_KEY)
            Task {
                await fetchRows();
            }
        }
        
    
        func fetchRows() async  {
            
            let result = try? await self.client?.database.from("tweets").select(columns: "*").execute();
            print("result:",result.debugDescription);
        }
    
    

    Steps to reproduce the behavior, please provide code snippets or a repository: I'm on release-candidate branch

    Expected behavior

    running python version - I get results back Screenshot 2022-11-18 at 7 45 15 am

    but on ios - I get results = nil

    Screenshots

    If applicable, add screenshots to help explain your problem.

    System information

    • OS: macos - ventura
    • Version of Node.js: swift release candidate branch 0.0.9

    Additional context

    I've successfully used and got data from superbase in another project - not sure what's going on here. maybe to do with async stuff?

    bug 
    opened by johndpope 5
  • Crashing On Query Execution

    Crashing On Query Execution

    MacOS: Monterey (12.2.2) XCode Version 13.3 (13E113)

    I seem to be having an issue getting this to work correctly. Trying to execute a query crashes as soon it begins. Although it could be a problem with my code as I'm fairly new to swift.

    My Environment variables are correct as I stepped through them before crash

    
    import SwiftUI
    import Supabase
    
    struct ContentView: View {
        @StateObject private var model = ContentViewModel()
        
    
        var body: some View {
            VStack {
                List(model.lessons) { lesson in
                            Text("\(lesson.title): \(lesson.description)")
                        }
            }
            .onAppear {
               model.getLessons()
            }
        }
    }
    
    class ContentViewModel: ObservableObject {
        @Published var lessons: [Lesson] = []    
        let supabaseUrl = URL(string: ProcessInfo.processInfo.environment["SUPABASE_URL"]!)
        let supabaseKey = ProcessInfo.processInfo.environment["SUPABASE_KEY"]!
        
        lazy var client = SupabaseClient(supabaseURL: supabaseUrl!,supabaseKey: supabaseKey)
        
    
        
        // Retrieve all lessons
        func getLessons() {
            print("Retrieving all todo's from database")
            
            let query = client.database.from("lessons")
                .select()
            
            query.execute { results in
                switch results {
                    case let .success(response):
                        let lessons = try? response.decoded(to: [Lesson].self)
                        self.lessons = lessons!
                    case let .failure(error):
                        print(error.localizedDescription)
                }
            }
            
        }
    
    }
    
    
    struct ContentView_Previews: PreviewProvider {
        static var previews: some View {
            ContentView()
        }
    }
    
    opened by DimitriMichel 5
  • consider supporting xcframworks

    consider supporting xcframworks

    had some success spitting this out

    https://github.com/mstfy/spm-to-xcframework

    /Users/johndpope/Desktop/spm-to-xcframework/.build/arm64-apple-macosx/release/spm-to-xcframework Sup abase --path /Users/johndpope/Desktop/supabase-swift --output /Users/johndpope/Desktop/xcframework

    Screen Shot 2022-08-31 at 11 23 17 am

    it's helpful for bazel builds

    opened by johndpope 4
  • URLSessionTransport is only available in iOS 13 or newer, but not constrained to that in RealtimeClient

    URLSessionTransport is only available in iOS 13 or newer, but not constrained to that in RealtimeClient

    Bug report

    Describe the bug

    URLSessionTransport is only available in iOS 13 or newer, but not constrained to that in RealtimeClient What I find interesting is that the version constraint is commented out. Is this by accident?

    Screenshots

    image

    System information

    • OS: macOS
    • Xcode 12
    • Version of supabase-swift: none, this package is based off a branch, not versions
    bug 
    opened by chFlorian 4
  • Auto-refreshing JWT randomly expires in 0.0.8

    Auto-refreshing JWT randomly expires in 0.0.8

    Auto-refresh now works, but only half the time

    It occasionally throws a PGRST301 error on query execution (401 on Supabase)

    Retrying the query multiple times fixes this, but I don't think it's a good solution long-term

    Maybe it issues a new token on query but passes only on the next one?

    opened by ooolzhas 3
  • Add PostgrestFilterBuilderSemantics

    Add PostgrestFilterBuilderSemantics

    Issue

    Issue Link

    What kind of change does this PR introduce?

    This PR introduces semantics updates for PostgrestFilterBuilder

    What is the current behavior?

    phfts(column: column, query: query, config: config)
    

    What is the new behavior?

    phrasetoFullTextSearch(column: String, query: String, config: String? = nil)
    

    Additional context

    The idea is to improve semantics by providing descriptive function names. These are implemented as an extension to PostgrestFilterBuilder, which allows to keep the existing function names (aka the mirrors of the JS library).

    opened by chFlorian 3
  • Insert doesn‘t return inserted row

    Insert doesn‘t return inserted row

    Using this code I insert a row into a todo table. Expectation was, that execute returns the row but it doesn‘t. But I need the inserted row because „id“ is an autogenerated column. Any way to achieve this?

    
    func createTodo(withTitle title: String) async {
            let todo = Todo(id: nil, title: title, done: false)
            let query = client
                .database
                .from("todos")
                .insert(values: todo)
            query.execute { results in
                switch results {
                case let .success(result):
                    print (result)
                    // self.todos.append(result.data) // I can‘t do that sice I receive no resulting data
                case let .failure(error):
                    Print(error.localizedDescription)
                }
            }
        }
    
    
    documentation 
    opened by unoctanium 2
  • Please introduce tags

    Please introduce tags

    Please introduce tags and releases to this package. As you know Swift Playgrounds 4 got released, but it only supports SPM packages by version number, not by branch. Thus it is currently impossible to use this SDK in a Playgrounds project.

    opened by chFlorian 2
  • OAuth Login with Auth Provider Example

    OAuth Login with Auth Provider Example

    Feature request

    I see in the gotrue RC pr the Google OAuth example was removed - https://github.com/supabase-community/gotrue-swift/pull/37/files#diff-5040cbf573fdc1b4fc2384e97402e4a832b40b22e33b3ff33fd0568db8e35ab1

    This was referenced in a few issues - https://github.com/supabase-community/supabase-swift/issues/39#issuecomment-1237818305 https://github.com/supabase-community/supabase-swift/issues/32#issuecomment-1168798055 (FWIW, I was never able to get that example working.. it would never redirect back to my app)

    Found another request for it https://www.reddit.com/r/Supabase/comments/xbjkt5/guidance_needed_in_relation_to_supabase_auth_swift/

    It's also being talked about in the community Discord channel (#swift) for something like this (?)

    I'd also like to add that I'm new to Swift and would be interested in a full blown example app I could clone and learn from... with auth, realtime, and databasing. There's a lot of examples on the Supabase website, just none in Swift!

    enhancement 
    opened by toystorynova 0
Releases(0.0.11)
Owner
Supabase
Supabase
Swift Markdown is a Swift package for parsing, building, editing, and analyzing Markdown documents.

Swift Markdown is a Swift package for parsing, building, editing, and analyzing Markdown documents.

Apple 2k Dec 28, 2022
Swift-DocC is a documentation compiler for Swift frameworks and packages aimed at making it easy to write and publish great developer documentation.

Swift-DocC is a documentation compiler for Swift frameworks and packages aimed at making it easy to write and publish great developer docum

Apple 833 Jan 3, 2023
Cross-Platform, Protocol-Oriented Programming base library to complement the Swift Standard Library. (Pure Swift, Supports Linux)

SwiftFoundation Cross-Platform, Protocol-Oriented Programming base library to complement the Swift Standard Library. Goals Provide a cross-platform in

null 620 Oct 11, 2022
Swift - ✏️Swift 공부 저장소✏️

Swift 스위프트의 기초 1. Swift의 기본 2. 변수와 상수 [3. 데이터 타입 기본] [4. 데이터 타입 고급] 5. 연산자 6. 흐름 제어 7. 함수 8. 옵셔널 객체지향 프로그래밍과 스위프트 9. 구조체와 클래스 10. 프로퍼티와 메서드 11. 인스턴스 생

Jiwon 0 Mar 9, 2022
Swift-ndi - Swift wrapper around NewTek's NDI SDK

swift-ndi Swift wrapper around NewTek's NDI SDK. Make sure you extracted latest

Alessio Nossa 12 Dec 29, 2022
__.swift is a port of Underscore.js to Swift.

__.swift Now, __.swift is version 0.2.0! With the chain of methods, __.swift became more flexible and extensible. Documentation: http://lotz84.github.

Tatsuya Hirose 86 Jun 29, 2022
SNTabBarDemo-Swift - Cool TabBar With Swift

SNTabBarDemo-Swift Cool TabBar How To Use // MARK: - setup private func setu

iAnchor 3 Sep 29, 2022
Swift-when - Expression switch support in Swift

Swift When - supporting switch expressions in Swift! What is it? Basically, it a

Gordan Glavaš 7 Nov 24, 2022
Swift-compute-runtime - Swift runtime for Fastly Compute@Edge

swift-compute-runtime Swift runtime for Fastly Compute@Edge Getting Started Crea

Andrew Barba 57 Dec 24, 2022
Swift-HorizontalPickerView - Customizable horizontal picker view component written in Swift for UIKit/iOS

Horizontal Picker View Customizable horizontal picker view component written in

Afraz Siddiqui 8 Aug 1, 2022
swift-highlight a pure-Swift data structure library designed for server applications that need to store a lot of styled text

swift-highlight is a pure-Swift data structure library designed for server applications that need to store a lot of styled text. The Highlight module is memory-efficient and uses slab allocations and small-string optimizations to pack large amounts of styled text into a small amount of memory, while still supporting efficient traversal through the Sequence protocol.

kelvin 4 Aug 14, 2022
Sovran-Swift: Small, efficient, easy. State Management for Swift

Sovran-Swift: Small, efficient, easy. State Management for Swift

Segment 5 Jan 3, 2023
Approximate is a Swift package that provides implementations of floating point comparisons for the Swift ecosystem

Approximate Approximate floating point equality comparisons for the Swift Programming Language. Introduction Approximate is a Swift package that provi

Christopher Blanchard 1 Jun 1, 2022
A Swift app, named 'iPose', for iPhone's pose measurement based on Swift.

iPhone's pose measurement based on Swift. This is a Swift app, named 'iPose', for iPhone's pose measurement based on Swift. This is a side project to

Ghasem Abdi 3 Jul 26, 2022
Swift Package Manager plugin which runs ActionBuilder to create a Github Actions workflow for a swift package.

ActionBuilderPlugin A Swift Package Manager command which builds a Github Actions workflow for the current package. By default the workflow file will

Elegant Chaos 4 Jul 20, 2022
Swift Server Implementation - RESTful APIs, AWS Lambda Serverless For Swift Runtime amazonlinux: AWS Lambda + API Gateway

Swift Server Implementation - RESTful APIs, AWS Lambda Serverless For Swift Runtime amazonlinux: AWS Lambda + API Gateway deployed on Graviton arm64 build swift:5.6.2-amazonlinux2-docker image

Furqan 2 Aug 16, 2022
A simple swift package that provides a Swift Concurrency equivalent to `@Published`.

AsyncValue This is a simple package that provides a convenience property wrapper around AsyncStream that behaves almost identically to @Published. Ins

Brent Mifsud 33 Oct 3, 2022
Zip - A Swift framework for zipping and unzipping files. Simple and quick to use. Built on top of minizip.

Zip A Swift framework for zipping and unzipping files. Simple and quick to use. Built on top of minizip. Usage Import Zip at the top of the Swift file

Roy Marmelstein 2.3k Jan 3, 2023
Soulful docs for Swift & Objective-C

jazzy is a command-line utility that generates documentation for Swift or Objective-C About Both Swift and Objective-C projects are supported. Instead

Realm 7.2k Jan 1, 2023