expo使ってるのでexpo-secure-storeでローカルの領域にjwt tokenを保存する
githubのコードはこちら
https://github.com/Raiu1210/onsen-mania-native/blob/master/components/screens/LoginScreen.js
とりあえず保存方
import React, { useState } from 'react';
import axios from 'axios';
import { useNavigation } from '@react-navigation/native';
import * as SecureStore from 'expo-secure-store';
const LoginScreen = () => {
const [email, setEmail] = useState('');
const [password, setPassword] = useState('');
const navigation = useNavigation();
const handleLogin = async () => {
try {
const response = await axios.post('https://login-endpoint', {
email,
password,
});
// ログイン成功の処理を行う
const token = response.data.access_token;
await SecureStore.setItemAsync('access_token', token);
navigation.navigate('Home');
} catch (error) {
// ログイン失敗の処理を行う
console.log(error);
Alert.alert('ログインエラー', 'ログインに失敗しました。');
}
};
return (
<View>
//
</View>
);
};
export default LoginScreen;