Depending on the authentication flows you offer in your app (for instance: Email Magic Links or Password Reset By Email), you may need to configure Stytch and your application to handle deeplinks.
In Xcode navigate to your target's "Info" tab and add a new entry under "URL Types"
Click the plus sign and choose a value to add to the "URL Schemes" field.
Adding your links as valid Redirect URLs in the Stytch Dashboard
For a more advanced implementation using Universal Links please refer to the following reading.
IOS Deep linking: URL Scheme vs Universal Links
In your SceneDelegate
file add the following code
func scene(_: UIScene, openURLContexts URLContexts: Set<UIOpenURLContext>) {
guard let url = URLContexts.first?.url else {
return
}
handle(url: url)
}
Add the following code to your root view.
.onOpenURL { url in
handle(url: url)
}
This handle method can be used for either UIKit or SwiftUI.
import StytchCore
func handle(url: URL) {
Task {
do {
switch try await StytchClient.handle(url: url, sessionDuration: 5) {
case let .handled(response):
switch responseData {
case let .auth(response):
print("handled .auth: \(response.session) - \(response.user)")
case let .oauth(response):
print("handled .oauth: \(response.session) - \(response.user)")
}
case .notHandled:
print("not handled")
case let .manualHandlingRequired(tokenType, token):
print("manualHandlingRequired: tokenType: \(tokenType) - token: \(token)")
}
} catch {
print("handle url error: \(error)")
}
}
}
For more information on the structure of Redirect URLs, consult our guide.