Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 14 additions & 11 deletions ios/ReactNativePasskeysModule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ final public class ReactNativePasskeysModule: Module, PasskeyResultHandler {
}

AsyncFunction("get") {
(request: PublicKeyCredentialRequestOptions, promise: Promise) throws in
(request: PublicKeyCredentialRequestOptions, requireBiometrics: Bool, promise: Promise) throws in
do {
// - all the throws are already in the helper `isAvailable` so we don't need to do anything
// ? this seems like a code smell ... what is the best way to do this
let _ = try isAvailable()
let _ = try isAvailable(requireBiometrics: requireBiometrics)
} catch let error {
throw error
}
Expand All @@ -54,11 +54,11 @@ final public class ReactNativePasskeysModule: Module, PasskeyResultHandler {
}.runOnQueue(.main)

AsyncFunction("create") {
(request: PublicKeyCredentialCreationOptions, promise: Promise) throws in
(request: PublicKeyCredentialCreationOptions, requireBiometrics: Bool, promise: Promise) throws in
do {
// - all the throws are already in the helper `isAvailable` so we don't need to do anything
// ? this seems like a code smell ... what is the best way to do this
let _ = try isAvailable()
let _ = try isAvailable(requireBiometrics: requireBiometrics)
} catch let error {
throw error
}
Expand Down Expand Up @@ -112,7 +112,7 @@ final public class ReactNativePasskeysModule: Module, PasskeyResultHandler {

}

private func isAvailable() throws -> Bool {
private func isAvailable(requireBiometrics: Bool = true) throws -> Bool {
if #unavailable(iOS 15.0) {
throw NotSupportedException()
}
Expand All @@ -121,7 +121,15 @@ final public class ReactNativePasskeysModule: Module, PasskeyResultHandler {
throw PendingPasskeyRequestException()
}

if LAContext().biometricType == .none {
let context = LAContext()

// Check the local authentication policy can be evaluated
let policy: LAPolicy = requireBiometrics ? .deviceOwnerAuthenticationWithBiometrics : .deviceOwnerAuthentication
guard context.canEvaluatePolicy(policy, error: nil) else {
throw BiometricException()
}

if requireBiometrics && context.biometricType == .none {
throw BiometricException()
}

Expand Down Expand Up @@ -457,11 +465,6 @@ extension LAContext {
var biometricType: BiometricType {
var error: NSError?

guard self.canEvaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, error: &error) else {
// Capture these recoverable error thru Crashlytics
return .none
}

if #available(iOS 11.0, *) {
switch self.biometryType {
case .none:
Expand Down
Loading