kopyl

Untitled

Aug 1st, 2025 (edited)
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Swift 1.09 KB | None | 0 0
  1. class AuthManager {
  2.     static let shared = AuthManager()
  3.    
  4.     let supabaseClient = SupabaseClient(
  5.         supabaseURL: URL(string: Environment.supabaseURL)!,
  6.         supabaseKey: Environment.supabaseAnonKey
  7.     )
  8.    
  9.     func addUserFullName(_ fullName: String) async throws {
  10.         guard !fullName.isEmpty else { return }
  11.         let attributes = UserAttributes(data: ["fullName": AnyJSON.string(fullName)])
  12.         try await supabaseClient.auth.update(user: attributes)
  13.     }
  14.    
  15.     func supabaseSignIn(idToken: String, nonce: String, fullName: String) async throws {
  16.         do {
  17.             let _ = try await supabaseClient.auth.signInWithIdToken(
  18.                 credentials: .init(provider: .apple, idToken: idToken, nonce: nonce)
  19.             )
  20.             try await addUserFullName(fullName)
  21.         } catch {
  22.             print("Supabase sign in failed: \(error)")
  23.             throw error
  24.         }
  25.     }
  26.    
  27.     @MainActor
  28.     func supabaseSignOut() async {
  29.         try? await supabaseClient.auth.signOut()
  30.         TransitionManager.shared.transitionToLogin()
  31.     }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment