How to integrate Supabase authentication in Swift.

Fredric Cliver
4 min readSep 30, 2023
https://supabase.com/auth

Install Supabase through the Swift package manager.

repo is here: https://github.com/supabase-community/supabase-swift

Swift package manager, Supabase-swift

Using SPM, install the supabase-swift package.

Code implementation

//
// AuthManager.swift
// Created by Fredric Cliver
//

import AuthenticationServices
import Foundation
@_spi(Experimental) import GoTrue
import Supabase

let MySupabaseUrlString: String = "https://{project-id}.supabase.co"
let MySupabaseUrl: URL = URL(string: "https://{project-id}.supabase.co")!
let MySupabaseKey: String =
"{supabase secret key}"

class AuthManager {
static let shared = AuthManager()
private init() {}

let supabaseClient = SupabaseClient(supabaseURL: MySupabaseUrl, supabaseKey: MySupabaseKey)

// referenced from https://github.com/supabase-community/supabase-swift/issues/89#issuecomment-1630223900
func loginWithAppleViaSupabase(
_ credential: ASAuthorizationAppleIDCredential, completion: @escaping (User?) -> Void
) {

guard
let idToken = credential.identityToken
.flatMap({ String(data: $0, encoding: .utf8) })
else {…

--

--

Fredric Cliver

Physics graduate with 13 years of diverse experience in the IT industry. Founded and managed a startup for 3 years.