UNPKG

@aaxis/react-native-secure-storage

Version:
81 lines (76 loc) 2.2 kB
/** * Sample React Native App * https://github.com/facebook/react-native * @flow */ import React, { Component } from 'react'; import { Platform, StyleSheet, Text, Alert, View } from 'react-native'; import SecureStorage, { ACCESS_CONTROL, ACCESSIBLE, AUTHENTICATION_TYPE } from 'react-native-secure-storage' const instructions = Platform.select({ ios: 'Press Cmd+R to reload,\n' + 'Cmd+D or shake for dev menu', android: 'Double tap R on your keyboard to reload,\n' + 'Shake or press menu button for dev menu', }); type Props = {}; export default class App extends Component<Props> { async componentDidMount() { const config = { accessControl: ACCESS_CONTROL.BIOMETRY_ANY_OR_DEVICE_PASSCODE, accessible: ACCESSIBLE.WHEN_UNLOCKED, accessGroup: null, authenticationPrompt: 'auth with yourself', service: 'example', authenticateType: AUTHENTICATION_TYPE.BIOMETRICS, } const key = 'key' await SecureStorage.setItem(key, 'vvvalue', config) // await SecureStorage.setItem(key + '1', 'vvvaaa1lue', config) // await SecureStorage.setItem(key + '2', 'value', config) // await SecureStorage.removeItem(key, config) const got = await SecureStorage.getItem(key, config) // const got = await SecureStorage.getAllKeys(config) // const got = await SecureStorage.canCheckAuthentication(config) Alert.alert(JSON.stringify(got)) // Alert.alert(JSON.stringify(await SecureStorage.getSupportedBiometryType())) } render() { return ( <View style={styles.container}> <Text style={styles.welcome}> Welcome to React Native! </Text> <Text style={styles.instructions}> To get started, edit App.js </Text> <Text style={styles.instructions}> {instructions} </Text> </View> ); } } const styles = StyleSheet.create({ container: { flex: 1, justifyContent: 'center', alignItems: 'center', backgroundColor: '#F5FCFF', }, welcome: { fontSize: 20, textAlign: 'center', margin: 10, }, instructions: { textAlign: 'center', color: '#333333', marginBottom: 5, }, });