Commit 7e8fdebf by G

clear async storage too to avoid being allowed into the app when reopen

parent a526018f
...@@ -6,14 +6,11 @@ import AsyncStorage from "@react-native-async-storage/async-storage"; ...@@ -6,14 +6,11 @@ import AsyncStorage from "@react-native-async-storage/async-storage";
// import { type NavigationProp, useNavigation } from "@react-navigation/native"; // import { type NavigationProp, useNavigation } from "@react-navigation/native";
import { useMutation } from "@tanstack/react-query"; import { useMutation } from "@tanstack/react-query";
import type { AxiosError } from "axios"; import type { AxiosError } from "axios";
import * as SplashScreen from "expo-splash-screen";
import { createContext, useCallback, useContext, useEffect, useState } from "react"; import { createContext, useCallback, useContext, useEffect, useState } from "react";
import type { IauthenticationData } from "./Types"; import type { IauthenticationData } from "./Types";
const log = LOG.extend("UserAuthenticationContext"); const log = LOG.extend("UserAuthenticationContext");
SplashScreen.preventAutoHideAsync();
export interface UserAuthenticationContextProps { export interface UserAuthenticationContextProps {
isAuthenticated: boolean; isAuthenticated: boolean;
setIsAuthenticated: React.Dispatch<React.SetStateAction<boolean>>; setIsAuthenticated: React.Dispatch<React.SetStateAction<boolean>>;
...@@ -159,36 +156,35 @@ export const UserAuthenticationContextProvider = ({ children }: { children: Reac ...@@ -159,36 +156,35 @@ export const UserAuthenticationContextProvider = ({ children }: { children: Reac
); );
const logout = useCallback(() => { const logout = useCallback(() => {
setIsAuthenticated(false); (async () => {
setAuthenticationData({ setIsAuthenticated(false);
access: "", setAuthenticationData({
refresh: "", access: "",
}); refresh: "",
setUserInformations({ });
username: "", setUserInformations({
email: "", username: "",
// biome-ignore lint/style/useNamingConvention: <explanation> email: "",
first_name: "",
// biome-ignore lint/style/useNamingConvention: <explanation>
last_name: "",
marchand: {
// biome-ignore lint/style/useNamingConvention: <explanation>
marchand_id: "",
nom: "",
code: "",
adresse: "",
// biome-ignore lint/style/useNamingConvention: <explanation> // biome-ignore lint/style/useNamingConvention: <explanation>
url_succes: "", first_name: "",
// biome-ignore lint/style/useNamingConvention: <explanation> // biome-ignore lint/style/useNamingConvention: <explanation>
url_echec: "", last_name: "",
entreprise: 0, marchand: {
user: 0, // biome-ignore lint/style/useNamingConvention: <explanation>
}, marchand_id: "",
}); nom: "",
// navigation.reset({ code: "",
// index: 0, adresse: "",
// routes: [{ name: "userLoginScreen" }], // biome-ignore lint/style/useNamingConvention: <explanation>
// }); url_succes: "",
// biome-ignore lint/style/useNamingConvention: <explanation>
url_echec: "",
entreprise: 0,
user: 0,
},
});
await clearStorages();
})();
}, []); }, []);
// Storages // Storages
...@@ -211,6 +207,15 @@ export const UserAuthenticationContextProvider = ({ children }: { children: Reac ...@@ -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 () => { const loadAuthenticationData = async () => {
log.debug("loadAuthenticationData | Loading authentication data"); log.debug("loadAuthenticationData | Loading authentication data");
const jsonRepresentation = await AsyncStorage.getItem("authenticationData"); const jsonRepresentation = await AsyncStorage.getItem("authenticationData");
...@@ -238,7 +243,6 @@ export const UserAuthenticationContextProvider = ({ children }: { children: Reac ...@@ -238,7 +243,6 @@ export const UserAuthenticationContextProvider = ({ children }: { children: Reac
} }
} catch (error) { } catch (error) {
} finally { } finally {
await SplashScreen.hideAsync();
} }
})(); })();
}, []); }, []);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment