diff --git a/src/contexts/UserAuthenticationContext.tsx b/src/contexts/UserAuthenticationContext.tsx index 24debc5..43adc9e 100644 --- a/src/contexts/UserAuthenticationContext.tsx +++ b/src/contexts/UserAuthenticationContext.tsx @@ -6,14 +6,11 @@ import AsyncStorage from "@react-native-async-storage/async-storage"; // import { type NavigationProp, useNavigation } from "@react-navigation/native"; import { useMutation } from "@tanstack/react-query"; import type { AxiosError } from "axios"; -import * as SplashScreen from "expo-splash-screen"; import { createContext, useCallback, useContext, useEffect, useState } from "react"; import type { IauthenticationData } from "./Types"; const log = LOG.extend("UserAuthenticationContext"); -SplashScreen.preventAutoHideAsync(); - export interface UserAuthenticationContextProps { isAuthenticated: boolean; setIsAuthenticated: React.Dispatch>; @@ -159,36 +156,35 @@ export const UserAuthenticationContextProvider = ({ children }: { children: Reac ); const logout = useCallback(() => { - setIsAuthenticated(false); - setAuthenticationData({ - access: "", - refresh: "", - }); - setUserInformations({ - username: "", - email: "", - // biome-ignore lint/style/useNamingConvention: - first_name: "", - // biome-ignore lint/style/useNamingConvention: - last_name: "", - marchand: { - // biome-ignore lint/style/useNamingConvention: - marchand_id: "", - nom: "", - code: "", - adresse: "", + (async () => { + setIsAuthenticated(false); + setAuthenticationData({ + access: "", + refresh: "", + }); + setUserInformations({ + username: "", + email: "", // biome-ignore lint/style/useNamingConvention: - url_succes: "", + first_name: "", // biome-ignore lint/style/useNamingConvention: - url_echec: "", - entreprise: 0, - user: 0, - }, - }); - // navigation.reset({ - // index: 0, - // routes: [{ name: "userLoginScreen" }], - // }); + last_name: "", + marchand: { + // biome-ignore lint/style/useNamingConvention: + marchand_id: "", + nom: "", + code: "", + adresse: "", + // biome-ignore lint/style/useNamingConvention: + url_succes: "", + // biome-ignore lint/style/useNamingConvention: + url_echec: "", + entreprise: 0, + user: 0, + }, + }); + await clearStorages(); + })(); }, []); // Storages @@ -211,6 +207,15 @@ export const UserAuthenticationContextProvider = ({ children }: { children: Reac } }; + const clearStorages = async () => { + try { + await AsyncStorage.clear(); + } catch (e) { + log.error("clearStorages |", e); + // saving error + } + }; + const loadAuthenticationData = async () => { log.debug("loadAuthenticationData | Loading authentication data"); const jsonRepresentation = await AsyncStorage.getItem("authenticationData"); @@ -238,7 +243,6 @@ export const UserAuthenticationContextProvider = ({ children }: { children: Reac } } catch (error) { } finally { - await SplashScreen.hideAsync(); } })(); }, []);