user1731387
user1731387

Reputation:

React native touch id not working

I want to create touch id local authentication in react native. I used

npm react-native-touch-id

import React, { Component } from 'react';
import {
  Platform,
  StyleSheet,
  Text,
  View,
  TouchableHighlight
} from 'react-native';

var LocalAuth = require('react-native-touch-id')

var YourComponent = React.createClass({
  _pressHandler() {
    LocalAuth.authenticate({
        reason: 'this is a secure area, please authenticate yourself',
        falbackToPasscode: true,    // fallback to passcode on cancel
        suppressEnterPassword: true // disallow Enter Password fallback
      })
      .then(success => {
        AlertIOS.alert('Authenticated Successfully')
      })
      .catch(error => {
        AlertIOS.alert('Authentication Failed', error.message)
      })
  },

  render() {
    return (
      <View>
        ...
        <TouchableHighlight onPress={this._pressHandler}>
          <Text>
            Authenticate with Touch ID / Passcode
          </Text>
        </TouchableHighlight>
      </View>
    )
  }
})

but it says nothing, i followed this link

https://github.com/ElekenAgency/react-native-touch-id-android

Upvotes: 0

Views: 2264

Answers (2)

Kapil Avaiya
Kapil Avaiya

Reputation: 148

use this code it worked for me !

import TouchID from 'react-native-touch-id';

TouchID.authenticate('Authentication')
     .then(success => {
              // Success code
            })
            .catch(error => {
              // Failure code
            });

Upvotes: 0

Dan
Dan

Reputation: 749

Came here because I've got the same question, but looking at your code I assume you've got lost in mixing libs.

Looking at the line:

var LocalAuth = require('react-native-touch-id')

You're importing LocalAuth which I believe is a part of react-native-local-auth library built on top of react-native-touch-id, while following a tutorial for 3-rd library which is react-native-touch-id-android.

According to their example in the repo, your import should look like this:

import Finger from 'react-native-touch-id-android'

My guess for the reason it's not crashing on you is because you've installed react-native-local-auth somewhere in the process befor trying out react-native-touch-id-android.

Better start all over - go to package.json and remove the above mentioned libraries, then run npm install and then follow the step-by-step guide in the repo you've posted.

I'd be glad if you come back afterwards and report on whether it worked out or not. Good luck.

Upvotes: 1

Related Questions