@gustash/react-native-smart-lock
Version:
Google Smart Lock for React Native
91 lines (70 loc) • 2.09 kB
Markdown
This package exposes Google Smart Lock for auto sign-in based on saved credentials.

`$ npm install @gustash/react-native-smart-lock --save`
`$ react-native link @gustash/react-native-smart-lock`
```javascript
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;
}
}
```
```javascript
import SmartLock from '@gustash/react-native-smart-lock';
async function save() {
const credentials = {
id: 'some@email.com',
profilePictureUri:
'https://api.adorable.io/avatars/285/abott@adorable.png',
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);
}
}
```
```javascript
import SmartLock from '@gustash/react-native-smart-lock';
async function deleteCredential() {
const error = await SmartLock.delete('some@email.com');
if (error) {
console.error(error);
}
}
```
```javascript
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();
```