Initialize and Authenticate
Add the Cloneable SDK to your app, initialize the SDK and authenticate
Initialize the SDK
Since we only want a single instance of the Cloneable SDK initialize the CloneablePlatform
class as a StateObject
.
Initialize the class with the following parameters:
authType
- enum (.jwt, .api)
api - input your API key, this will not auth a specific user but auth the SDK broadly with the permissions of the API key
JWT: The SDK does not currently support JWT auth. Only use API key based auth.
import CloneablePlatformiOS
@main
struct Example_App: App {
// CloneablePlatform conforms to ObservableObject
@StateObject private var cloneable: CloneablePlatform = CloneablePlatform(authType: .api, apiKey: "YOUR_API_KEY")
var body: some Scene {
WindowGroup {
ContentView()
.environmentObject(cloneable) // Pass the SDK reference as an environment object
}
}
}
Pass the SDK as an environment variable to child views
We recommend passing the reference of the Cloneable SDK as an environment to the view hierarchy. This makes it easy to access the SDK across your child views using the following
struct ChildView: View {
@EnvironmentObject var cloneable: CloneablePlatform
...
}
Authenticate
The SDK provides several variables and helper functions to both determine the current auth status and auth a user into the platform
API based auth
You must your API key to the CloneablePlatform initializer.
Auth status
You can determine if a user is authed into the platform by accessing the userAuthed
published variable from CloneablePlatform
Example usage:
struct ChildView: View {
@EnvironmentObject var cloneable: CloneablePlatform
var body: some View {
Group {
switch cloneable.authStatus {
case .authenticated:
MainAppView()
case .not_authenticated:
Text("Not authenticated")
case .loading:
ProgressView("Authenticating...")
}
}
}
}
Last updated