Skip to content

Clerk helps developers build user management. We provide streamlined user experiences for your users to sign up, sign in, and manage their profile.

License

Notifications You must be signed in to change notification settings

clerk/clerk-ios

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation


Official Clerk iOS SDK (Beta)

Clerk helps developers build user management. We provide streamlined user experiences for your users to sign up, sign in, and manage their profile.

chat on Discord documentation twitter

ℹ️ 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!


πŸš€ Get Started with Clerk

  1. Sign up for an account
  2. Create an application in your Clerk dashboard
  3. Spin up a new codebase with the quickstart guide

πŸ§‘β€πŸ’» Installation

Swift Package Manager

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")
]

πŸ› οΈ Usage

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")
      }
    }
  }
}

Authentication

Sign Up with Email and Perform Verification

// 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"))

Passwordless Sign In

// 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"))

Sign In with OAuth (e.g. Google, Github, etc.)

try await SignIn.authenticateWithRedirect(strategy: .oauth(provider: .google))

Native Sign in with Apple

// 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)

Forgot Password

// 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))

Sign Out

try await clerk.signOut()

User Management

Update User Profile

try await user.update(.init(firstName: "John", lastName: "Appleseed"))

Update User Profile Image

let imageData = try await photosPickerItem.loadTransferable(type: Data.self)
try await user.setProfileImage(imageData: imageData)

Link an External Account

let externalAccount = try await user.createExternalAccount(provider: .github)
try await externalAccount.reauthorize()

For a full set of features and functionality, please see our docs!

πŸŽ“ Docs

βœ… Supported Features

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 ❌

🚒 Release Notes

Curious what we shipped recently? Check out our changelog!

πŸ“ License

This project is licensed under the MIT license.

See LICENSE for more information.

About

Clerk helps developers build user management. We provide streamlined user experiences for your users to sign up, sign in, and manage their profile.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages