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,6 +156,7 @@ export const UserAuthenticationContextProvider = ({ children }: { children: Reac ...@@ -159,6 +156,7 @@ export const UserAuthenticationContextProvider = ({ children }: { children: Reac
); );
const logout = useCallback(() => { const logout = useCallback(() => {
(async () => {
setIsAuthenticated(false); setIsAuthenticated(false);
setAuthenticationData({ setAuthenticationData({
access: "", access: "",
...@@ -185,10 +183,8 @@ export const UserAuthenticationContextProvider = ({ children }: { children: Reac ...@@ -185,10 +183,8 @@ export const UserAuthenticationContextProvider = ({ children }: { children: Reac
user: 0, user: 0,
}, },
}); });
// navigation.reset({ await clearStorages();
// index: 0, })();
// routes: [{ name: "userLoginScreen" }],
// });
}, []); }, []);
// 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