GithubHelp home page GithubHelp logo

dylanhillier / react-native-smart-lock Goto Github PK

View Code? Open in Web Editor NEW

This project forked from gustash/react-native-smart-lock

0.0 0.0 0.0 301 KB

React Native implementation of Android Smart Lock

License: MIT License

JavaScript 15.26% Ruby 14.33% Objective-C 11.87% Java 53.06% Starlark 5.48%

react-native-smart-lock's Introduction

React Native Smart Lock

This package exposes Google Smart Lock for auto sign-in based on saved credentials.

Getting started

$ npm install @gustash/react-native-smart-lock --save

Mostly automatic installation (RN < 0.60)

$ react-native link @gustash/react-native-smart-lock

Usage

Request Credentials

import SmartLock from '@gustash/react-native-smart-lock';

async function request() {
  // You can also send a client server id as a paramenter as well
  // const {error, success, ...credentials} = await SmartLock.request('some.server.id');
  const {error, success, ...credentials} = await SmartLock.request();

  if (error) {
    console.error(error);
    return;
  }

  if (success) {
    // Account found. Do something with credentials.
    const {
      id,
      password,
      accountType,
      familyName,
      givenName,
      name,
      profilePictureUri,
      idTokens,
    } = credentials;
  }
}

Save Credentials

import SmartLock from '@gustash/react-native-smart-lock';

async function save() {
  const credentials = {
    id: '[email protected]',
    profilePictureUri:
      'https://api.adorable.io/avatars/285/[email protected]',
    name: 'John Doe',
    password: 'password',
  };

  const error = await SmartLock.save(credentials);

  // The save method might be canceled if the system wants to give priority
  // to the password manager UI instead.
  if (error && error !== 'canceled') {
    console.error(error);
  }
}

Delete Credentials

import SmartLock from '@gustash/react-native-smart-lock';

async function deleteCredential() {
  const error = await SmartLock.delete('[email protected]');

  if (error) {
    console.error(error);
  }
}

Disable Auto Sign-in

import SmartLock from '@gustash/react-native-smart-lock';

// This disables request() until a new save() is called.
// You should call this on logout to allow the user to change accounts, for example.
SmartLock.disableAutoSignIn();

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.