An object that can be used to pause or resume listening for OS credentials (i.e. fingerprint, face recognition) and to cancel the whole operation while listening for credentials.

IMPORTANT
The OsAuthenticationListenHandler class is Android specific.

This is used with Aaid.BIOMETRIC, Aaid.DEVICE_PASSCODE and Aaid.FINGERPRINT authenticator attestation identifiers.

Methods

  • Pauses listening for OS credentials.

    If the application is listening for OS credentials, and it is brought to the background, then the operating system will cancel automatically listening for credentials and will send an error. This method must be invoked when the application is brought to the background before the OS cancels the authentication and the SDK sends an error.

    Invoking this method will have effect only if cancelAuthentication was not previously invoked.

    The method can be invoked from the AppState event listener when the new state is inactive or background and the current state is active. Note that this approach does not work in some devices (in these devices the event listener is invoked after the OS cancels the authentication).

    For example:

       const appState = useRef(AppState.currentState);
    const [listenHandler, setListenHandler] = useState<OsAuthenticationListenHandler>();

    useCallback(() => {
    const onStateChange = async (nextAppState: AppStateStatus) => {
    if (appState.current === 'active' && nextAppState.match(/inactive|background/)) {
    if (listenHandler !== undefined) {
    await listenHandler.pauseListening()
    .then((newListenHandler) => {
    setListenHandler(newListenHandler);
    })
    .catch(ErrorHandler.handle.bind(null, OperationType.unknown));
    }
    }

    appState.current = nextAppState;
    };

    const subscription = AppState.addEventListener('change', onStateChange);
    return () => subscription.remove();
    }, [appState, listenHandler]);

    Returns Promise<OsAuthenticationListenHandler>

    the OsAuthenticationListenHandler to handle the new listening.

  • Resumes listening for OS credentials.

    If the application is listening for OS credentials and it is brought to the background, then the operating system will cancel automatically listening for credentials. This method must be invoked when the application is brought to the foreground again to resume listening for credentials.

    Invoking this method will have effect only if cancelAuthentication was not previously invoked.

    The method is typically invoked from the AppState event listener when the new state is active and the current state is inactive or background.

    For example:

       const appState = useRef(AppState.currentState);
    const [listenHandler, setListenHandler] = useState<OsAuthenticationListenHandler>();

    useCallback(() => {
    const onStateChange = async (nextAppState: AppStateStatus) => {
    if (appState.current.match(/inactive|background/) && nextAppState === 'active') {
    if (listenHandler !== undefined) {
    await listenHandler.resumeListening()
    .then((newListenHandler) => {
    setListenHandler(newListenHandler);
    })
    .catch(ErrorHandler.handle.bind(null, OperationType.unknown));
    }
    }

    appState.current = nextAppState;
    };

    const subscription = AppState.addEventListener('change', onStateChange);
    return () => subscription.remove();
    }, [appState, listenHandler]);

    Returns Promise<OsAuthenticationListenHandler>

    the OsAuthenticationListenHandler to handle the new listening.