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 { useRouter } from 'expo-router'
|
||||||
import { FAB, List, Surface } from 'react-native-paper'
|
import { FAB, List, Surface } from 'react-native-paper'
|
||||||
import * as SecureStore from 'expo-secure-store'
|
|
||||||
|
|
||||||
export default function HistoryScreen() {
|
export default function HistoryScreen() {
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
|
@ -1,7 +1,8 @@
|
|||||||
|
import SecureStore from "@/utils/SecureStore"
|
||||||
import { useRouter } from "expo-router"
|
import { useRouter } from "expo-router"
|
||||||
import { useRef, useState } from "react"
|
import { useRef, useState } from "react"
|
||||||
|
import { Platform } from "react-native"
|
||||||
import { Button, Dialog, Portal, Surface, Text, TextInput } from "react-native-paper"
|
import { Button, Dialog, Portal, Surface, Text, TextInput } from "react-native-paper"
|
||||||
import * as SecureStore from 'expo-secure-store'
|
|
||||||
|
|
||||||
export default function Login() {
|
export default function Login() {
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
@ -28,15 +29,19 @@ export default function Login() {
|
|||||||
setErrorTitle("Erreur")
|
setErrorTitle("Erreur")
|
||||||
setErrorText("Une erreur inconnue est survenue lors de la connexion. Veuillez réessayer plus tard. " + err)
|
setErrorText("Une erreur inconnue est survenue lors de la connexion. Veuillez réessayer plus tard. " + err)
|
||||||
})
|
})
|
||||||
console.log(resp)
|
if (!resp)
|
||||||
if (resp.error) {
|
return
|
||||||
|
else if (resp.error) {
|
||||||
setErrorDialogVisible(true)
|
setErrorDialogVisible(true)
|
||||||
setErrorTitle(resp.error)
|
setErrorTitle(resp.error)
|
||||||
setErrorText(resp.message)
|
setErrorText(resp.message)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
SecureStore.setItem("apiName", name)
|
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("apiPassword", password)
|
||||||
|
}
|
||||||
SecureStore.setItem("apiToken", resp.accessToken)
|
SecureStore.setItem("apiToken", resp.accessToken)
|
||||||
router.back()
|
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