fix fetch data to work even with autologin true
This commit is contained in:
parent
5d8abaf66a
commit
dfd419e438
2 changed files with 12 additions and 9 deletions
|
|
@ -103,13 +103,6 @@ export default function App() {
|
||||||
if (isAuthenticated) {
|
if (isAuthenticated) {
|
||||||
try {
|
try {
|
||||||
await setupAxiosDefaults();
|
await setupAxiosDefaults();
|
||||||
|
|
||||||
const res = await getGlobalVariables();
|
|
||||||
setGlobalVariables(res);
|
|
||||||
|
|
||||||
checkHasStore();
|
|
||||||
fetchApiData();
|
|
||||||
|
|
||||||
resolve();
|
resolve();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Failed to fetch data:", error);
|
console.error("Failed to fetch data:", error);
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,13 @@
|
||||||
import { createContext, useEffect, useState } from "react";
|
import { createContext, useEffect, useState } from "react";
|
||||||
import { useNavigate } from "react-router-dom";
|
import { useNavigate } from "react-router-dom";
|
||||||
import Cookies from "universal-cookie";
|
import Cookies from "universal-cookie";
|
||||||
import { getLoggedUser, requestLogout } from "../controllers/API";
|
import { getGlobalVariables, getLoggedUser, requestLogout } from "../controllers/API";
|
||||||
import useAlertStore from "../stores/alertStore";
|
import useAlertStore from "../stores/alertStore";
|
||||||
import { useFolderStore } from "../stores/foldersStore";
|
import { useFolderStore } from "../stores/foldersStore";
|
||||||
import { Users } from "../types/api";
|
import { Users } from "../types/api";
|
||||||
import { AuthContextType } from "../types/contexts/auth";
|
import { AuthContextType } from "../types/contexts/auth";
|
||||||
|
import { useGlobalVariablesStore } from "../stores/globalVariablesStore/globalVariables";
|
||||||
|
import { useStoreStore } from "../stores/storeStore";
|
||||||
|
|
||||||
const initialValue: AuthContextType = {
|
const initialValue: AuthContextType = {
|
||||||
isAdmin: false,
|
isAdmin: false,
|
||||||
|
|
@ -45,6 +47,11 @@ export function AuthProvider({ children }): React.ReactElement {
|
||||||
);
|
);
|
||||||
|
|
||||||
const getFoldersApi = useFolderStore((state) => state.getFoldersApi);
|
const getFoldersApi = useFolderStore((state) => state.getFoldersApi);
|
||||||
|
const setGlobalVariables = useGlobalVariablesStore(
|
||||||
|
(state) => state.setGlobalVariables,
|
||||||
|
);
|
||||||
|
const checkHasStore = useStoreStore((state) => state.checkHasStore);
|
||||||
|
const fetchApiData = useStoreStore((state) => state.fetchApiData);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const storedAccessToken = cookies.get("access_token_lf");
|
const storedAccessToken = cookies.get("access_token_lf");
|
||||||
|
|
@ -66,8 +73,11 @@ export function AuthProvider({ children }): React.ReactElement {
|
||||||
setUserData(user);
|
setUserData(user);
|
||||||
const isSuperUser = user!.is_superuser;
|
const isSuperUser = user!.is_superuser;
|
||||||
setIsAdmin(isSuperUser);
|
setIsAdmin(isSuperUser);
|
||||||
|
|
||||||
getFoldersApi(true, true);
|
getFoldersApi(true, true);
|
||||||
|
const res = await getGlobalVariables();
|
||||||
|
setGlobalVariables(res);
|
||||||
|
checkHasStore();
|
||||||
|
fetchApiData();
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue