You can also use our SDK to help determine when to display a passkey creation prompt based on whether or not the user has an existing passkey available on their device.
Copy
Ask AI
let showPrompt = await authsignal.passkey.shouldPromptToCreatePasskey()if showPrompt { let response = await authsignal.passkey.signUp( token: "eyJhbGciOiJIUzI....", username: "jane.smith@authsignal.com", ignorePasskeyAlreadyExistsError: true, )}
A formatted error code which may additionally be present if the SDK call encountered an error.
Possible values are: token_not_set, expired_token, network_error or user_canceled.
Calling signIn will present the passkey sign-in prompt if a credential is available on the device.
If the user successfully authenticates with their passkey, send the result token to your server to validate the challenge.
Copy
Ask AI
let response = await authsignal.passkey.signIn(action: "signInWithPasskey")if let token = response.data?.token { // Send token to your backend for validation}
Because some users may not have a passkey available, you can conditionally present a fallback authentication method by handling error codes returned by the SDK.
A string which determines how the action associated with the passkey sign-in attempt will be named
in the Authsignal Portal. Values are validated with the following
regex: ^[a-zA-Z0-9_-]{(1, 64)}$.
If set to true, the passkey prompt will not be shown when no credentials are available on the
device and an error code will be
returned.
Defaults to true. Set this to false if you want to support signing in with credentials on another
device via QR code.
A formatted error code which may additionally be present if the SDK call encountered an error.
Possible values are: user_canceled or no_credential (Android only). These values can be
used to handle if a passkey is not available on the
device.
Passkeys are supported from iOS 15 and Android API level 28 or higher.You can detect whether or not the current device supports passkeys by using the isSupported helper method.
This feature requires rendering a text field with the textContentType property.
Copy
Ask AI
userTextField.textContentType = .username
Then when the screen loads, you should initialize the text field for passkey autofill by running the following code.
Copy
Ask AI
let result = await authsignal.passkey.signIn( action: "signInWithPasskeyAutofill", autofill: true)if let token = result.data?.token { // The user has focused your text input and authenticated with an existing passkey // Send the response token to your server to validate the result of the challenge}