Utilisation du stockage navigateur local
This commit is contained in:
parent
32460062b8
commit
62559810b0
@ -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()
|
||||
|
@ -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)
|
||||
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()
|
||||
}
|
||||
|
3
client/utils/SecureStore.native.ts
Normal file
3
client/utils/SecureStore.native.ts
Normal file
@ -0,0 +1,3 @@
|
||||
import * as SecureStore from 'expo-secure-store'
|
||||
|
||||
export default SecureStore
|
17
client/utils/SecureStore.ts
Normal file
17
client/utils/SecureStore.ts
Normal 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 }
|
Loading…
Reference in New Issue
Block a user