Ricardo Teixeira
Ricardo Teixeira

Reputation: 51

Expo authentication

i am currently using expo authentication to set the biometrics, it is working so far , but the fallback option is to use cellphone PIN, but i don't know how to capture if my pin code worked successfully, where can i capture the pin successfull message in react native?

see my code below


import * as LocalAuthentication from 'expo-local-authentication'

export const handleBiometricAuth = async () => {
  const isBiometricAvailable = await LocalAuthentication.hasHardwareAsync()

  if (!isBiometricAvailable) {
    Alert.alert('Please, enter your pin', 'biometric auth not supported', [
      {
        text: 'ok',
        onPress: () => console.log('fallback'),
      },
    ])

    return false
  }

  const savedBiometrics = await LocalAuthentication.isEnrolledAsync()

  if (!savedBiometrics) {
    Alert.alert('Attention', 'You should enable your biometrics or pin ', [
      {
        text: 'ok',
        onPress: () => console.log('fallback'),
      },
    ])

    return false
  }

  const biometricAuth = await LocalAuthentication.authenticateAsync({
    promptMessage: 'Login With Biometrics',
    // cancelLabel: 'Cancel',
    // disableDeviceFallback: true,
  })

  if (biometricAuth.success) {
    return true
  }

  return false
}```

Upvotes: 1

Views: 842

Answers (1)

srinivasa rao pedada
srinivasa rao pedada

Reputation: 164

const biometricAuth = await LocalAuthentication.authenticateAsync({
    promptMessage: 'Login With Biometrics',
    cancelLabel: 'Cancel',
    disableDeviceFallback: false,
  })

  if (biometricAuth.success) {
  // ======> Here for both biometric or pin/passcode based successful login .success object will be returned
    return true
  }

Upvotes: 2

Related Questions