Clerk helps developers build user management. We provide streamlined user experiences for your users to sign up, sign in, and manage their profile.
βΉοΈ While minor breaking changes (method names, parameter names, etc.) can be expected until version 1.0.0, the iOS SDK is considered stable.
Clerk is Hiring!
Would you like to work on Open Source software and help maintain this repository? Apply today!
- Sign up for an account
- Create an application in your Clerk dashboard
- Spin up a new codebase with the quickstart guide
To integrate using Apple's Swift Package Manager, navigate to your Xcode project, select Package Dependencies
and click the +
icon to search for https://github.com/clerk/clerk-ios
.
Alternatively, add the following as a dependency to your Package.swift
:
dependencies: [
.package(url: "https://github.com/clerk/clerk-ios", from: "0.1.0")
]
First, configure Clerk in your app's entry point:
import SwiftUI
import Clerk
@main
struct ClerkQuickstartApp: App {
@State private var clerk = Clerk.shared
var body: some Scene {
WindowGroup {
ContentView()
.environment(clerk)
.task {
clerk.configure(publishableKey: "your_publishable_key")
try? await clerk.load()
}
}
}
}
Now in your views, you can conditionally render content based on the user's session:
import SwiftUI
import Clerk
struct ContentView: View {
@Environment(Clerk.self) private var clerk
var body: some View {
VStack {
if let user = clerk.user {
Text("Hello, \(user.id)")
} else {
Text("You are signed out")
}
}
}
}
// Create a sign up
var signUp = try await SignUp.create(
strategy: .standard(emailAddress: "[email protected]", password: "β’β’β’β’β’β’β’β’β’β’β’β’")
)
// Check if the SignUp needs the email address verified and send an OTP code via email.
if signUp.unverifiedFields.contains("email_address") {
signUp = try await signUp.prepareVerification(strategy: .emailCode)
}
// After collecting the OTP code from the user, attempt verification
signUp = try await signUp.attemptVerification(strategy: .emailCode(code: "12345"))
// Create the sign in
var signIn = try await SignIn.create(
strategy: .identifier("[email protected]", strategy: "email_code")
)
// After collecting the OTP code from the user, attempt verification
signIn = try await signIn.attemptFirstFactor(for: .emailCode(code: "12345"))
try await SignIn.authenticateWithRedirect(strategy: .oauth(provider: .google))
// Use the Clerk SignInWithAppleHelper class to get your Apple credential
let credential = try await SignInWithAppleHelper.getAppleIdCredential()
// Convert the identityToken data to String format
guard let idToken = credential.identityToken.flatMap({ String(data: $0, encoding: .utf8) }) else { return }
// Authenticate with Clerk
try await SignIn.authenticateWithIdToken(provider: .apple, idToken: idToken)
// Create a sign in and send an OTP code to verify the user owns the email.
var signIn = try await SignIn.create(
strategy: .identifier("[email protected]", strategy: "reset_password_email_code")
)
// After collecting the OTP code from the user, attempt verification.
signIn = try await signIn.attemptFirstFactor(for: .resetPasswordEmailCode(code: "12345"))
// Set a new password to complete the process.
signIn = try await signIn.resetPassword(.init(password: "β’β’β’β’β’β’β’β’β’β’β’β’", signOutOfOtherSessions: true))
try await clerk.signOut()
try await user.update(.init(firstName: "John", lastName: "Appleseed"))
let imageData = try await photosPickerItem.loadTransferable(type: Data.self)
try await user.setProfileImage(imageData: imageData)
let externalAccount = try await user.createExternalAccount(provider: .github)
try await externalAccount.reauthorize()
For a full set of features and functionality, please see our docs!
Feature | iOS Support |
---|---|
Email/Phone/Username Authentication | β |
Email Code Verification | β |
SMS Code Verification | β |
Multi-Factor Authentication (TOTP / SMS) | β |
Sign in / Sign up with OAuth | β |
Native Sign in with Apple | β |
Session Management | β |
Multi-Session Applications | β |
Forgot Password | β |
User Management | β |
Passkeys | β |
Enterprise SSO (SAML) | β |
Device Attestation | β |
Organizations | β |
Prebuilt UI Components | β |
Magic Links | β |
Sign Up via Invitation | β |
Web3 Wallet | β |
Curious what we shipped recently? Check out our changelog!
This project is licensed under the MIT license.
See LICENSE for more information.