Member-only story

How to integrate Supabase authentication in Swift.

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
Fredric Cliver

Written by Fredric Cliver

13+ years in the digital trenches. I decode complex tech concepts into actionable insights, focusing on AI, Software Engineering, and emerging technologies.

Responses (2)