diff --git a/client/app/login.tsx b/client/app/login.tsx index 8a775cd..4721655 100644 --- a/client/app/login.tsx +++ b/client/app/login.tsx @@ -7,7 +7,7 @@ import { Appbar, Button, Dialog, Portal, Surface, Text, TextInput } from "react- export default function Login() { const router = useRouter() const [isLoggedIn, setIsLoggedIn] = useState(SecureStore.getItem("apiToken") !== null) - console.log(SecureStore.getItem("apiToken")) + const [loggingIn, setLoggingIn] = useState(false) const [name, setName] = useState(SecureStore.getItem('apiName') ?? "") const [password, setPassword] = useState("") const [errorDialogVisible, setErrorDialogVisible] = useState(false) @@ -20,6 +20,9 @@ export default function Login() { const hideErrorDialog = () => setErrorDialogVisible(false) async function login() { + if (loggingIn) + return + setLoggingIn(true) const resp = await fetch("http://192.168.1.198:3000/auth/login/", { method: "POST", headers: { "Content-Type": "application/json" }, @@ -30,6 +33,7 @@ export default function Login() { setErrorDialogVisible(true) setErrorTitle("Erreur") setErrorText("Une erreur inconnue est survenue lors de la connexion. Veuillez réessayer plus tard. " + err) + setLoggingIn(false) }) if (!resp) return @@ -37,8 +41,10 @@ export default function Login() { setErrorDialogVisible(true) setErrorTitle(resp.error) setErrorText(resp.message) + setLoggingIn(false) return } + setLoggingIn(false) 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 @@ -80,7 +86,13 @@ export default function Login() { onSubmitEditing={login} secureTextEntry={true} style={{ margin: 8 }} /> - diff --git a/client/utils/background.ts b/client/utils/background.ts index c91fdf2..fc290f8 100644 --- a/client/utils/background.ts +++ b/client/utils/background.ts @@ -4,15 +4,13 @@ import { Platform } from 'react-native' import { useEffect } from 'react' const BACKGROUND_FETCH_TASK = "background-fetch" -const BACKGROUND_FETCH_INTERVAL = 20 +const BACKGROUND_FETCH_INTERVAL = 60 async function backgroundUpdate() { - async () => { - const now = Date.now() - console.log(`Got background fetch call at date: ${new Date(now).toISOString()}`) - // Be sure to return the successful result type! - return BackgroundFetch.BackgroundFetchResult.NewData - } + const now = Date.now() + console.log(`Got background fetch call at date: ${new Date(now).toISOString()}`) + // Be sure to return the successful result type! + return BackgroundFetch.BackgroundFetchResult.NewData } TaskManager.defineTask(BACKGROUND_FETCH_TASK, backgroundUpdate)