feat(ui): added new auth guard with react-query and axios

This commit is contained in:
akhilmhdh
2023-01-26 00:14:01 +05:30
parent a6f480d3f8
commit a6387e7552
16 changed files with 234 additions and 30 deletions
+21
View File
@@ -0,0 +1,21 @@
import { QueryClient } from '@tanstack/react-query';
// this is saved in react-query cache
export const AUTH_TOKEN_CACHE_KEY = ['infisical__auth-token'];
export const queryClient = new QueryClient({
defaultOptions: {
queries: {
refetchOnWindowFocus: false,
retry: 1
}
}
});
// set token in memory cache
export const setAuthToken = (token: string) =>
queryClient.setQueryData(AUTH_TOKEN_CACHE_KEY, token);
export const getAuthToken = () => queryClient.getQueryData(AUTH_TOKEN_CACHE_KEY) as string;
export const isLoggedIn = () => Boolean(getAuthToken());