1.0.1 • Published 4 years ago

react-native-expo-auth v1.0.1

Weekly downloads
2
License
MIT
Repository
github
Last release
4 years ago

react-native-expo-auth

React Native Expo Component that provides Sign In, Sign Up, Reset Password flows for user authentication. The component includes an API for FaceID and TouchID (iOS) and Fingerprint API (Android) to authenticate the user with a face or fingerprint scan.

Autocomplete Example

Installation

$ npm install --save react-native-expo-auth

or

$ yarn add react-native-expo-auth

Usage

// ...


import React, { useState } from "react";
import { Authenticate } from "react-native-expo-auth";

const ExampleApp = props => {

    const [isVisible, setIsVisible] = useState(true);
    const [logins, setLogins] = useState(["test@gmail.com"]);

    /**
     * Each callback should return object that contains success and/or error.
     * @param {Object} data
     * @returns {{ success: Boolean, error: String }}
     */
    const submitAuth = async(data, route) => {
        const signUpRaw = await fetch(`http://test.com/${route}`, {
            method: "POST", 
            body: JSON.stringify(data)
        });
        if(signUpRaw.status !== 200) {
            return {
                success: false,
                error: await signUpRaw.text()
            };
        }
        const { emails } = await signUpRaw.json();
        setLogins(emails);
        return {
            success: true
        };
    };

    const submitSignIn = async (data) => await submitAuth(data, "signin");
    const submitSignUp = async (data) => await submitAuth(data, "signup");
    const submitBioLogin = async (data) => await submitAuth(data, "biologin");
    const submitPinCodeRequest = async (data) => await submitAuth(data, "reset");
    const submitNewPassword = async (data) => await submitAuth(data, "doreset");

    render() {
        return (
            <Authenticate
                visible={isVisible}
                onLogin={submitSignIn} 
                onSignUp={submitSignUp}
                onBioLogin={submitBioLogin}
                logins={logins}
                onPinCodeRequest={submitPinCodeRequest}
                onSubmitNewPassword={submitNewPassword}
                enableBio={true}
            >
                <Text>YOUR LOGO</Text>
                <Image
                    source={require("./images/logo.png")}
                />
            </Authenticate>
        );
    }

};

// ...

Props

PropTypeDescription
visiblebooleanSet to true to show the component. By default visible is set to true.
onLoginfunctionCallback will be called once user submits login form.
onSignUpfunctionCallback will be called once user submits submit form.
onBioLoginfunctionCallback will be called once user uses Mobile Biometric Check( faceId, fingerprint or Pin Code).
loginsarrayAn array of logins which a user is allowed to use during bioLogin. Logins get populated when a user signs in/up using a specific device.
onPinCodeRequestfunctionCallback that will be called if a user submits forgot password form.
onSubmitNewPasswordfunctionCallback will be called once a user submits a new password after resetting the old one.
enableBiobooleanEnables/Disables Mobile Biometric Check.

Contribute

Feel free to open issues or do a PR!