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