Enrollment

Example for how to enroll a new user.

🔌 Trigger

You are now ready to start the enrollment. Suppose you have an "Enroll" button and a corresponding trigger where you invoke the Keyless.shared.enrollCustomToken method.

Depending on your application logic, you can choose to use different custom token. This could be a secret that you have provided to the app from the backend, the seed of an OTP protocol, or anything else. If you only need to know the result of the authentication (success/failed), you can pass any constant value as the custom token.

func tappedEnrollButton(_ sender: Any) {
do {
try Keyless.shared.enrollCustomToken(with: "Your custom token")
} catch {
print(error)
}
}

Optionally, start a loading indicator and show the progress by implementing two of the optional Keyless delegate methods:

func enrollmentDidStart() {
DispatchQueue.main.async { [weak self] in
// Start loading indicator
}
}
func enrollmentDidProgress(progress: Float) {
DispatchQueue.main.async { [weak self] in
// Update the loading indicator to display `progress`
}
}

😎 Result

When enrollment finishes, the enrollmentDidFinish: keylessID: enrollmentResponse: error: method gets called. Note the keylessID of the user. In case of errors, prompt the user to try again.

If the process was successful, stop the loading indicator and navigate to the next screen of your application (e.g. success or main view).

func enrollmentDidFinish(keylessID: String?, enrollmentResponse: String?, error: KeylessError?) {
guard error == nil else {
print("enrollmentDidFail", error!)
DispatchQueue.main.async {
// Display an error to the user.
}
return
}
// Stop the loading indicator
// Display success to the user
}