f-23 / react-native-passkey

Passkeys for React Native
MIT License
131 stars 30 forks source link

types not present in Passkey.js node_modules #40

Closed dmarcosc closed 1 month ago

dmarcosc commented 2 months ago

Hello, I have been facing this error where I add the library and when building my app I get

node_modules/react-native-passkey/lib/module/index.js (1:45): "PasskeyAuthenticationResult" is not exported by "node_modules/react-native-passkey/lib/module/Passkey.js", imported by "node_modules/react-native-passkey/lib/module/index.js".

for context I am using yarn, and this happens in both a react-native app and a ts library f I check my node_modules/react-native-passkey/lib/module/Passkey.js these types are indeed not present this is the content of Passkey.js

import { NotSupportedError } from './PasskeyError';
import { Platform } from 'react-native';
import { PasskeyAndroid } from './PasskeyAndroid';
import { PasskeyiOS } from './PasskeyiOS';
export class Passkey {
  /**
   * Creates a new Passkey
   *
   * @param request The FIDO2 Attestation Request in JSON format
   * @param options An object containing options for the registration process
   * @returns The FIDO2 Attestation Result in JSON format
   * @throws
   */
  static async register(request) {
    let {
      withSecurityKey
    } = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {
      withSecurityKey: false
    };
    if (!Passkey.isSupported) {
      throw NotSupportedError;
    }
    if (Platform.OS === 'android') {
      return PasskeyAndroid.register(request);
    }
    return PasskeyiOS.register(request, withSecurityKey);
  }

  /**
   * Authenticates using an existing Passkey
   *
   * @param request The FIDO2 Assertion Request in JSON format
   * @param options An object containing options for the authentication process
   * @returns The FIDO2 Assertion Result in JSON format
   * @throws
   */
  static async authenticate(request) {
    let {
      withSecurityKey
    } = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {
      withSecurityKey: false
    };
    if (!Passkey.isSupported) {
      throw NotSupportedError;
    }
    if (Platform.OS === 'android') {
      return PasskeyAndroid.authenticate(request);
    }
    return PasskeyiOS.authenticate(request, withSecurityKey);
  }

  /**
   * Checks if Passkeys are supported on the current device
   *
   * @returns A boolean indicating whether Passkeys are supported
   */
  static async isSupported() {
    if (Platform.OS === 'android') {
      return Platform.Version > 28;
    }
    if (Platform.OS === 'ios') {
      return parseInt(Platform.Version, 10) > 15;
    }
    return false;
  }
}

/**
 * The available options for Passkey operations
 */
//# sourceMappingURL=Passkey.js.map
ZoltanSzokodi commented 1 month ago

I am also facing this at the moment. Did you apply a patch or any other suggestions?

P.S. - I just patched it for now. It was causing a compile error on web for me. On native I haven't even noticed it 🤷‍♂️

diff --git a/node_modules/react-native-passkey/lib/module/index.js b/node_modules/react-native-passkey/lib/module/index.js
index ca16465..4be1d1c 100644
--- a/node_modules/react-native-passkey/lib/module/index.js
+++ b/node_modules/react-native-passkey/lib/module/index.js
@@ -1,3 +1,3 @@
-import { Passkey, PasskeyRegistrationResult, PasskeyAuthenticationResult } from './Passkey';
-export { Passkey, PasskeyRegistrationResult, PasskeyAuthenticationResult };
+import { Passkey } from './Passkey';
+export { Passkey };
 //# sourceMappingURL=index.js.map
\ No newline at end of file
dmarcosc commented 1 month ago

I solved it adding the dependancy on vite.config.ts rolloutoptions, and everything seems to work normally

rollupOptions: {
                external: [
                    'react',
                    'react-dom',
                    'react/jsx-runtime',
                    'react-native',
                    '@tanstack/react-query',
                    'react-native-passkey'
                ],
                treeshake: true
            }