Help us understand the problem. What is going on with this article?

RactNative(Expo)でSecureStoreを利用する。

秘密鍵情報やsecret等の保存は悩ましいところです。
ExpoではSecureStoreという、iOSだと、Keychain Servicesを、AndroidならKeystore Systemをラップした保存手法を提供してくれます。AsyncStoreとほぼ同じ感じで使えるようです。

App.js

実装は以下の通り。特に難しいことはありません。セットしない、deleteした場合はnullが返るようです。

App.js
import React from 'react';
import { StyleSheet, Text, View, Button } from 'react-native';
import { SecureStore } from 'expo';

export default class App extends React.Component {
    render() {
        return (
            <View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
                <Button
                    title='setItem'
                    onPress={() => this.handleSetItem()}
                />
                <Button
                    title='getItem'
                    onPress={() => this.handleGetItem()}
                />
                <Button
                    title='deleteItem'
                    onPress={() => this.handleDeleteItem()}
                />
            </View>
        );
    }

    handleSetItem = async () => {
        await SecureStore.setItemAsync('access_key', 'hoge');
        alert('setItem');
    }

    handleGetItem = async () => {
        const key = await SecureStore.getItemAsync('access_key');
        if (key === null) {
            alert('セットされていません。');
        } else {
            alert(key);
        }
    }

    handleDeleteItem = async () => {
        await SecureStore.deleteItemAsync('access_key');
        alert('deleteItem');
    }
}

Why do not you register as a user and use Qiita more conveniently?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away