CuriousUser is a lightweight Swift library that allows iOS developers to support guest user sessions in their apps. It provides tools to manage guest and authenticated user states, gate features based on user session, and prompt users to upgrade when needed.
- Session Management: Easily manage guest and authenticated user sessions.
- Feature Access Control: Gate features based on user session state.
- Upgrade Prompt: A customizable SwiftUI view to prompt guest users to sign up or log in.
- Designed for SwiftUI: Optimized for SwiftUI apps with iOS 17+ support.
- Open your Xcode project.
- Go to File > Add Packages.
- Enter the URL of this repository:
https://github.com/obvios/curious-user.git
. - Select the latest version and add it to your project.
Alternatively, you can add it directly to your Package.swift
file:
dependencies: [
.package(url: "https://github.com/obvios/curious-user.git", from: "1.0.0")
]
import CuriousUser
let sessionManager = SessionManager()
let features = [
Feature(id: "browse_catalog", name: "Browse Catalog", accessLevel: .guest),
Feature(id: "premium_insights", name: "Premium Insights", accessLevel: .authenticated)
]
let featureGateManager = FeatureGateManager(sessionManager: sessionManager, features: features)
if featureGateManager.isFeatureAccessible(featureID: "premium_insights") {
print("Feature is accessible")
} else {
print("Feature requires login")
}
import SwiftUI
struct ContentView: View {
@EnvironmentObject var sessionManager: SessionManager
var body: some View {
if case .authenticated = sessionManager.sessionState {
Text("Welcome to Premium Features!")
} else {
UpgradePromptView(
title: "Premium Feature",
message: "Log in to unlock premium content.",
actionTitle: "Log In"
) {
print("Redirect to login or sign-up screen")
}
}
}
}
- iOS 17+
- Swift 5.7+
Contributions are welcome! Feel free to submit issues or pull requests to help improve the library.
This project is licensed under the MIT License. See the LICENSE file for details.