• Stars
    star
    104
  • Rank 330,604 (Top 7 %)
  • Language
    Objective-C
  • Created almost 9 years ago
  • Updated over 4 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

React Native authentication with iOS Passcode.

React Native Passcode Auth

npm version npm downloads

React Native Passcode Auth is a React Native library for authenticating users with iOS Passcode. It is an excellent fallback for when Touch ID is not available.

react-native-passcode-auth

Documentation

Install

React Native Passcode Auth requires iOS 9.0 or later.

npm i --save react-native-passcode-auth

Usage

Linking the Library

In order to use Passcode Auth, you must first link the library to your project. There's excellent documentation on how to do this in the React Native Docs.

Requesting Passcode Authentication

Once you've linked the library, you'll want to make it available to your app by requiring it:

import PasscodeAuth from 'react-native-passcode-auth';

Requesting Passcode authentication is as simple as calling:

PasscodeAuth.authenticate('to demo this react-native component')
  .then(success => {
    // Success code
  })
  .catch(error => {
    // Failure code
  });

Example

Using PasscodeAuth in your app will usually look like this:

import React, { Component, AlertIOS, TouchableHighlight, View, Text } from 'react-native';
import PasscodeAuth form 'react-native-passcode-auth';

class YourComponent extends Component {
  _pressHandler() {
    PasscodeAuth.authenticate('to demo this react-native component')
      .then(success => {
        AlertIOS.alert('Authenticated Successfully');
      })
      .catch(error => {
        AlertIOS.alert('Authentication Failed');
      });
  }

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

Methods

authenticate(reason)

Attempts to authenticate with Passcode. Returns a Promise object.

Arguments

  • reason - An optional String that provides a clear reason for requesting authentication.

Examples

PasscodeAuth.authenticate('to demo this react-native component')
  .then(success => {
    // Success code
    console.log('User authenticated with Passcode');
  })
  .catch(error => {
    // Failure code
    console.log(error);
  });

isSupported()

Verify's that Passcode Auth is supported and that Passcode is set. Returns a Promise object.

Examples

PasscodeAuth.isSupported()
  .then(supported => {
    // Success code
    console.log('Passcode Auth is supported.');
  })
  .catch(error => {
    // Failure code
    console.log(error);
  });

Errors

There are various reasons why authenticating with Passcode may fail. Whenever calling Passcode authentication fails, PasscodeAuth.authenticate will return an error code representing the reason.

Below is a list of error codes that can be returned:

Code Description
LAErrorAuthenticationFailed Authentication was not successful because the user failed to provide valid credentials.
LAErrorUserCancel Authentication was canceled by the user—for example, the user tapped Cancel in the dialog.
LAErrorUserFallback Authentication was canceled because the user tapped the fallback button (Enter Password).
LAErrorSystemCancel Authentication was canceled by system—for example, if another application came to foreground while the authentication dialog was up.
LAErrorPasscodeNotSet Authentication could not start because the passcode is not set on the device.
PasscodeAuthNotSet Authentication could not start because the passcode is not set on the device.
PasscodeAuthNotSupported Device does not support Passcode Auth.

More information on errors can be found in Apple's Documentation.

License

Copyright (c) 2015, Naoufal Kadhom

Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

More Repositories

1

react-native-payments

Accept Payments with Apple Pay and Android Pay using the Payment Request API.
JavaScript
1,589
star
2

react-native-touch-id

React Native authentication with the native Touch ID popup.
Java
1,475
star
3

react-native-safari-view

A React Native wrapper for Safari View Controller.
Objective-C
495
star
4

react-native-activity-view

iOS share and action sheets for React Native
Objective-C
481
star
5

react-native-accordion

An Accordion Component for React Native
JavaScript
437
star
6

react-native-speech

A text-to-speech library for React Native.
Objective-C
304
star
7

react-native-progress-hud

A clean and lightweight progress HUD for your React Native app.
JavaScript
258
star
8

disable-react-devtools

🚫 Disables the React DevTools from your production application.
JavaScript
42
star
9

react-native-resources

A list of React Native components, libraries, examples and videos.
24
star
10

universal-config

Configuration for your Universal JavaScript apps.
JavaScript
16
star
11

react-progress-hud

A clean and lightweight progress HUD for your React app.
JavaScript
13
star
12

react-native-context-menu

JavaScript
4
star
13

configo

Hierarchical configuration with files and environment variables for node and the browser
JavaScript
4
star
14

hockeystreams

A node.js wrapper for the HockeySteams API.
JavaScript
3
star
15

node-se-cli

A Selenium command line interface.
JavaScript
3
star
16

frmt

A utility library to format strings.
JavaScript
3
star
17

nkProgressHUD

nkProgressHUD is a web HUD to preoccupy users during server-side tasks.
JavaScript
2
star
18

docs

Crew API Documentation
2
star
19

higher-order

A simple JavaScript utility for composing higher-order components
JavaScript
1
star
20

loser

Have an L ✨
JavaScript
1
star
21

iphone-6-availability

I'm tired of checking availability.
JavaScript
1
star
22

nkVanilla

My vanilla template for new projects
Ruby
1
star
23

selector

A lightweight DOM element selector helper library.
1
star
24

apple-pay-backend

JavaScript
1
star
25

dotfiles

Preferences and settings for my toolbox.
Vim Script
1
star
26

nkSideMenu

nkSideMenu is a responsive side menu template for your web app.
JavaScript
1
star