Utilisation du stockage navigateur local

This commit is contained in:
Emmy D'Anello 2024-12-09 22:47:22 +01:00
parent 32460062b8
commit 62559810b0
Signed by: ynerant
GPG Key ID: 3A75C55819C8CF85
4 changed files with 30 additions and 5 deletions

View File

@ -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()

View File

@ -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()
}

View File

@ -0,0 +1,3 @@
import * as SecureStore from 'expo-secure-store'
export default SecureStore

View File

@ -0,0 +1,17 @@
export function getItem(key: string): string | null {
return localStorage.getItem(key)
}
export async function getItemAsync(key: string): Promise<string | null> {
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<void> {
localStorage.setItem(key, value)
}
export default { getItem, getItemAsync, setItem, setItemAsync }