Socket
Socket
Sign inDemoInstall

rn-biometric-authentication

Package Overview
Dependencies
0
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    rn-biometric-authentication

React Native library biometric authentication.


Version published
Weekly downloads
111
decreased by-33.13%
Maintainers
1
Created
Weekly downloads
 

Readme

Source

React Native Biometric Auth

React native biometric Auth is a bridge to Android/iOS for biometric authentication.

Feature List

  1. Check if Biometric authentication enabled on the device.
  2. Authenticate user using Biometric with a fallback mechanism to passcode or device password.
  3. Supported on both Android and iOS.

How to use

Installation

npm i rn-biometric-authentication

On React Native 0.60+ the CLI autolink feature links the module while building the app.

Additional configuration

iOS

This package requires an iOS target SDK version of iOS 10 or higher

Ensure that you have the NSFaceIDUsageDescription entry set in your react native iOS project, or Face ID will not work properly. This description will be will be presented to the user the first time a biometrics action is taken, and the user will be asked if they want to allow the app to use Face ID. If the user declines the usage of face id for the app, the isSensorAvailable function will indicate biometrics is unavailable until the face id permission is specifically allowed for the app by the user.

Android

This package requires a compiled SDK version of 29 (Android 10.0) or higher

Methods

isSensorAvailable()

Detects what type of biometric sensor is available. Returns a Promise that resolves to an object with details about biometrics availability

Result Object

PropertyTypeDescription
availableboolA boolean indicating if biometrics is available or not
biometryTypestringA string indicating what type of biometrics is available. TouchID(iOS), FaceID(iOS), Biometrics(Android), or undefined if biometrics is not available.
errorstringAn error message indicating why biometrics may not be available. undefined if there is no error.

Example

import ReactNativeBiometricAuth from 'rn-biometric-authentication'

ReactNativeBiometricAuth.isSensorAvailable()
  .then((resultObject) => {
    const { available, biometryType } = resultObject

    if (available && biometryType === ReactNativeBiometrics.TouchID) {
      console.log('ReactNativeBiometricAuth', 'TouchID is supported')
    } else if (available && biometryType === ReactNativeBiometrics.FaceID) {
      console.log('ReactNativeBiometricAuth', 'FaceID is supported')
    } else if (available && biometryType === ReactNativeBiometrics.Biometrics) {
      console.log('ReactNativeBiometricAuth', 'Biometrics is supported')
    } else {
      console.log('ReactNativeBiometricAuth', 'Biometrics not supported')
    }
  })

simplePrompt(options)

Prompts the user for their fingerprint or face id. Returns a Promise that resolves if the user provides a valid biometrics or cancel the prompt, otherwise the promise rejects.

Options Object

ParameterTypeDescriptioniOSAndroid
promptMessagestringMessage that will be displayed in the biometrics prompt
cancelButtonTextstringText to be displayed for the cancel button on biometric prompts, defaults to Cancel
isDeviceAuthEnabledbooleanEnable fallback to device credential for authentication.
fallbackTextstringFallback text to be displayed for passcode if TouchID or FaceID authentication failed.

Result Object

PropertyTypeDescription
successboolA boolean indicating if the biometric prompt succeeded, false if the users cancels the biometrics prompt
errorstringAn error message indicating why the biometric prompt failed. undefined if there is no error.

Example

import ReactNativeBiometricAuth from 'rn-biometric-authentication'

ReactNativeBiometricAuth.simplePrompt({promptMessage: 'Authenticate'})
  .then((resultObject) => {
    const { success } = resultObject

    if (success) {
      console.log('ReactNativeBiometricAuth', 'Success')
    } else {
      console.log('ReactNativeBiometricAuth', 'Cancelled')
    }
  })
  .catch(() => {
    console.log('ReactNativeBiometricAuth', 'Failed')
  })

Inspiration

This library uses some code from react-native-biometrics. Added options to fallback to the device credentials for authentication. Removed some feature to make it simple to use for authentication purpose only.

Keywords

FAQs

Last updated on 09 Nov 2020

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc