addPasskey method

  1. @override
Future<Passkey> addPasskey(
  1. PasskeyCreationOptions? options
)
override

Implementation

@override
Future<Passkey> addPasskey(PasskeyCreationOptions? options) async {
  final passkeysSupported = await deviceSupportsPasskeys();
  if (!passkeysSupported) {
    throw PassageError(code: PassageErrorCode.passkeysNotSupported);
  }
  try {
    final jsOptions = js_util.jsify(options?.toJson());
    final resultPromise = passage.getCurrentUser().addDevice(jsOptions);
    final jsObject = await js_util.promiseToFuture(resultPromise);
    return Passkey.fromJson(jsObject);
  } catch (e) {
    final error = PassageError.fromObject(
        object: e, overrideCode: PassageErrorCode.passkeyError);
    if (error.message.contains('failed to parse public key')) {
      throw PassageError(
          code: PassageErrorCode.userCancelled, message: error.message);
    }
    throw error;
  }
}