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";
// 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<React.SetStateAction<boolean>>;
......@@ -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: <explanation>
first_name: "",
// biome-ignore lint/style/useNamingConvention: <explanation>
last_name: "",
marchand: {
// biome-ignore lint/style/useNamingConvention: <explanation>
marchand_id: "",
nom: "",
code: "",
adresse: "",
(async () => {
setIsAuthenticated(false);
setAuthenticationData({
access: "",
refresh: "",
});
setUserInformations({
username: "",
email: "",
// biome-ignore lint/style/useNamingConvention: <explanation>
url_succes: "",
first_name: "",
// biome-ignore lint/style/useNamingConvention: <explanation>
url_echec: "",
entreprise: 0,
user: 0,
},
});
// navigation.reset({
// index: 0,
// routes: [{ name: "userLoginScreen" }],
// });
last_name: "",
marchand: {
// biome-ignore lint/style/useNamingConvention: <explanation>
marchand_id: "",
nom: "",
code: "",
adresse: "",
// biome-ignore lint/style/useNamingConvention: <explanation>
url_succes: "",
// biome-ignore lint/style/useNamingConvention: <explanation>
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();
}
})();
}, []);
......
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