From 1f4cfe0b774c78ebd8a814e4918846c605404263 Mon Sep 17 00:00:00 2001 From: Emmy D'Anello Date: Mon, 9 Dec 2024 22:57:59 +0100 Subject: [PATCH] Correction secure store --- client/app/(tabs)/settings.tsx | 2 +- client/app/login.tsx | 7 +++++-- client/utils/SecureStore.native.ts | 3 --- client/utils/SecureStore.ts | 18 ++---------------- client/utils/SecureStore.web.ts | 15 +++++++++++++++ 5 files changed, 23 insertions(+), 22 deletions(-) delete mode 100644 client/utils/SecureStore.native.ts create mode 100644 client/utils/SecureStore.web.ts diff --git a/client/app/(tabs)/settings.tsx b/client/app/(tabs)/settings.tsx index ed48b65..498a790 100644 --- a/client/app/(tabs)/settings.tsx +++ b/client/app/(tabs)/settings.tsx @@ -1,4 +1,4 @@ -import SecureStore from '@/utils/SecureStore' +import * as SecureStore from '@/utils/SecureStore' import { useRouter } from 'expo-router' import { FAB, List, Surface } from 'react-native-paper' diff --git a/client/app/login.tsx b/client/app/login.tsx index 288a2a4..59fc8f5 100644 --- a/client/app/login.tsx +++ b/client/app/login.tsx @@ -1,4 +1,4 @@ -import SecureStore from "@/utils/SecureStore" +import * as SecureStore from "@/utils/SecureStore" import { useRouter } from "expo-router" import { useRef, useState } from "react" import { Platform } from "react-native" @@ -43,7 +43,10 @@ export default function Login() { SecureStore.setItem("apiPassword", password) } SecureStore.setItem("apiToken", resp.accessToken) - router.back() + if (router.canGoBack()) + router.back() + else + router.navigate('/') } return ( diff --git a/client/utils/SecureStore.native.ts b/client/utils/SecureStore.native.ts deleted file mode 100644 index cf3700f..0000000 --- a/client/utils/SecureStore.native.ts +++ /dev/null @@ -1,3 +0,0 @@ -import * as SecureStore from 'expo-secure-store' - -export default SecureStore diff --git a/client/utils/SecureStore.ts b/client/utils/SecureStore.ts index 62ccad9..bbb51aa 100644 --- a/client/utils/SecureStore.ts +++ b/client/utils/SecureStore.ts @@ -1,17 +1,3 @@ -export function getItem(key: string): string | null { - return localStorage.getItem(key) -} +import { getItem, getItemAsync, setItem, setItemAsync } from 'expo-secure-store' -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 } +export { getItem, getItemAsync, setItem, setItemAsync } diff --git a/client/utils/SecureStore.web.ts b/client/utils/SecureStore.web.ts new file mode 100644 index 0000000..77adfbc --- /dev/null +++ b/client/utils/SecureStore.web.ts @@ -0,0 +1,15 @@ +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) +}