react-native-keychain
react-native-keychain copied to clipboard
AppState and getGenericPassword
Good afternoon. Can you please tell me how to implement this approach, always request biometrics (getGenericPassword), when we change AppState to 'active'.
Right now I have a loop, as the FaceID screen - first makes the screen 'inactive', and when it activates successfully it makes it back to 'active' and then the loop goes on.
My code:
useEffect(() => {
const listenerChangeAppState = async (state: string) => {
if (state === 'active') {
const credentials = await getGenericPassword();
....
}
};
const appListener = AppState.addEventListener('change', listenerChangeAppState);
return () => appListener.remove();
}, []);
Store the state in a ref when it is changed. Only update it when the state is different from the previous state, and only do this when the state is 'active' or 'background'.