How to integrate Supabase authentication in Swift.
4 min readSep 30, 2023
Install Supabase through the Swift package manager.
repo is here: https://github.com/supabase-community/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 {…