diff --git a/client/app/(tabs)/settings.tsx b/client/app/(tabs)/settings.tsx index 413ddc2..ed48b65 100644 --- a/client/app/(tabs)/settings.tsx +++ b/client/app/(tabs)/settings.tsx @@ -1,6 +1,6 @@ +import SecureStore from '@/utils/SecureStore' import { useRouter } from 'expo-router' import { FAB, List, Surface } from 'react-native-paper' -import * as SecureStore from 'expo-secure-store' export default function HistoryScreen() { const router = useRouter() diff --git a/client/app/login.tsx b/client/app/login.tsx index 7300f21..288a2a4 100644 --- a/client/app/login.tsx +++ b/client/app/login.tsx @@ -1,7 +1,8 @@ +import SecureStore from "@/utils/SecureStore" import { useRouter } from "expo-router" import { useRef, useState } from "react" +import { Platform } from "react-native" import { Button, Dialog, Portal, Surface, Text, TextInput } from "react-native-paper" -import * as SecureStore from 'expo-secure-store' export default function Login() { const router = useRouter() @@ -28,15 +29,19 @@ export default function Login() { setErrorTitle("Erreur") setErrorText("Une erreur inconnue est survenue lors de la connexion. Veuillez réessayer plus tard. " + err) }) - console.log(resp) - if (resp.error) { + if (!resp) + return + else if (resp.error) { setErrorDialogVisible(true) setErrorTitle(resp.error) setErrorText(resp.message) return } SecureStore.setItem("apiName", name) - SecureStore.setItem("apiPassword", password) + if (Platform.OS !== "web") { + // Le stockage navigateur n'est pas sûr, on évite de stocker un mot de passe à l'intérieur + SecureStore.setItem("apiPassword", password) + } SecureStore.setItem("apiToken", resp.accessToken) router.back() } diff --git a/client/utils/SecureStore.native.ts b/client/utils/SecureStore.native.ts new file mode 100644 index 0000000..cf3700f --- /dev/null +++ b/client/utils/SecureStore.native.ts @@ -0,0 +1,3 @@ +import * as SecureStore from 'expo-secure-store' + +export default SecureStore diff --git a/client/utils/SecureStore.ts b/client/utils/SecureStore.ts new file mode 100644 index 0000000..62ccad9 --- /dev/null +++ b/client/utils/SecureStore.ts @@ -0,0 +1,17 @@ +export function getItem(key: string): string | null { + return localStorage.getItem(key) +} + +export async function getItemAsync(key: string): Promise { + return localStorage.getItem(key) +} + +export function setItem(key: string, value: string): void { + localStorage.setItem(key, value) +} + +export async function setItemAsync(key: string, value: string): Promise { + localStorage.setItem(key, value) +} + +export default { getItem, getItemAsync, setItem, setItemAsync }