- For Firebase: [SZSFirebaseAuth]TODO
- For Supabase: [SZSSupabaseAuth]TODO
- For RestAPI: [SZSRestAuth]TODO
Reason: SZSAuthManager is being deprecated to focus on provider-specific authentication solutions, allowing for deeper integration with each provider's unique features. This approach simplifies maintenance, reduces complexity, and enables more efficient updates tailored to individual authentication services.
SZSAuthManager is a flexible authentication management system for Swift applications. It supports multiple authentication providers and offers a unified interface for common authentication operations.
- Support for multiple authentication providers (Firebase, REST API, Supabase)
- Unified interface for authentication operations
- Built-in user model (SZSUser)
- Combine-based asynchronous operations
- Easy to extend with new authentication providers
Add the following to your Package.swift
file:
dependencies: [
.package(url: "https://github.com/assad62/SZSAuthManager.git", from: "1.0.0")
]
Use the Builder pattern to create an instance of SZSAuthManager:
import SZSAuth
func readGoogleServiceInfo() -> [String: Any]? {
guard let plistPath = Bundle.main.path(forResource: "GoogleService-Info", ofType: "plist"),
let plistContent = NSDictionary(contentsOfFile: plistPath) as? [String: Any] else {
print("Failed to read GoogleService-Info.plist")
return nil
}
return plistContent
}
let firebaseConfig = FirebaseConfig(plistContent: readGoogleServiceInfo()!)
let authManager = SZSAuthManager.Builder(authProvider: .firebase)
.setFirebaseConfig(firebaseConfig)
.build()
authManager.signIn(email: "user@example.com", password: "password")
.sink(receiveCompletion: { completion in
switch completion {
case .finished:
print("Sign in completed")
case .failure(let error):
print("Sign in failed: \(error)")
}
}, receiveValue: { user in
print("Signed in user: \(user)")
})
.store(in: &cancellables)
authManager.signUp(email: "newuser@example.com", password: "password", name: "New User")
.sink(receiveCompletion: { completion in
// Handle completion
}, receiveValue: { user in
print("Signed up user: \(user)")
})
.store(in: &cancellables)
authManager.signOut()
.sink(receiveCompletion: { completion in
// Handle completion
}, receiveValue: {
print("User signed out")
})
.store(in: &cancellables)
authManager.getCurrentUser()
.sink(receiveValue: { user in
if let user = user {
print("Current user: \(user)")
} else {
print("No user is currently signed in")
}
})
.store(in: &cancellables)
authManager.sendVerificationEmail()
.sink(receiveCompletion: { completion in
switch completion {
case .finished:
print("Verification email sent successfully")
case .failure(let error):
print("Failed to send verification email: \(error)")
}
}, receiveValue: { _ in })
.store(in: &cancellables)
authManager.deleteUser()
.sink(receiveCompletion: { completion in
// Handle completion
}, receiveValue: {
print("User account deleted")
})
.store(in: &cancellables)
SZSAuthManager is particularly useful in the following scenarios:
-
Multi-platform Applications: Provides a consistent authentication interface across iOS, macOS, and tvOS.
-
White-Label Applications: Easily switch between auth providers for different branded versions of your app.
-
Transitioning Between Auth Providers: Gradually migrate from one auth system to another.
-
Applications with Multiple Auth Methods: Abstract away differences between various authentication methods.
-
Testing and Development: Create mock authentication services for testing or local development.
- Firebase
- REST API
- Supabase
To use a different provider, change the authProvider
parameter when creating the SZSAuthManager and provide the appropriate configuration.
To add a custom authentication provider:
- Create a new case in the
AuthProvider
enum. - Implement a new
AuthService
conforming to theAuthService
protocol. - Add a new configuration type if needed.
- Update the
SZSAuthManager.Builder
to handle the new provider.
[Add your license information here]
[Add support information, such as how to report issues or where to ask questions]