iOS Quickstart (Beta)
You will learn the following:
- Create a new Xcode project
- Install the Clerk iOS SDK
- Configure
Clerk
with your Publishable Key - Use Clerk to enable users to sign in and out of your application
Before you start
Disable bot protection
Bot protection is enabled by default for all Clerk apps. However, it is not supported in native apps.
To turn off bot protection:
- In the Clerk Dashboard, navigate to the Attack protection page.
- Disable Bot sign-up protection.
Create an iOS Project
To get started using Clerk with iOS, create a new project in Xcode. Select SwiftUI as your interface and Swift as your language. See the Xcode documentation for more information.
Install the Clerk iOS SDK
Follow the Swift Package Manager instructions to install Clerk as a dependency. When prompted for the package URL, enter https://github.com/clerk/clerk-ios. Be sure to add the package to your target.
Load Clerk
To use Clerk in your app, you must first configure and load Clerk
.
- Inside your new project in Xcode, open your
@main
app file. - Import
ClerkSDK
. - Add a new variable
clerk
marked with the@ObservedObject
property wrapper. - Replace
ContentView()
with the belowZStack
. - Attach a
.task
modifier to the newZStack
. In the body of the task, configureclerk
with your Publishable Key, and then loadclerk
. You can get your Publishable Key from the API keys page in the Clerk Dashboard.
Conditionally render content
To render content based on whether a user is authenticated or not:
- Open your
ContentView
file. - Import
ClerkSDK
. - Add a new variable
clerk
marked with the@ObservedObject
property wrapper. - Replace the content of the view body with a conditional that checks for a
clerk.user
.
Create views for sign-up and sign-in
SignUpView
The following example creates a SignUpView
that allows users to sign up using their email address and password, and sends an email verification code to confirm their email address.
SignInView
The following example creates a SignInView
that allows users to sign in using their email address and password.
SignUpOrSignInView
Finally, create a SignUpOrSignInView
container view that allows users to switch between sign up and sign in.
Allow users to sign up or sign in
Go back to your ContentView
and render your newly created SignUpOrSignInView
when the user isn't signed in.
Allow users to sign out
Finally, provide users with a way to sign out of your app:
- Open your
ContentView
. - Add a button that ends a user's session.
Feedback
Last updated on