🔧 fix(App.tsx): fix linting issues and add missing dependencies to useEffect hook
🔧 fix(authContext.tsx): change localStorage to cookies for storing access token 🔧 fix(api.tsx): remove console.log statement 🔧 fix(AdminPage/index.tsx): add missing import for getLoggedUser function and useContext for AuthContext
This commit is contained in:
parent
75c1499eaa
commit
dc4b757a02
4 changed files with 20 additions and 1 deletions
|
|
@ -127,6 +127,19 @@ export default function App() {
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const { setUserData, getAuthentication, isAuthenticated } = useContext(AuthContext);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
setTimeout(() => {
|
||||||
|
if(getAuthentication && !isLoginPage){
|
||||||
|
getLoggedUser().then((user) => {
|
||||||
|
setUserData(user);
|
||||||
|
}).catch((error) => {});
|
||||||
|
}
|
||||||
|
}, 1000);
|
||||||
|
},[]);
|
||||||
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
//need parent component with width and height
|
//need parent component with width and height
|
||||||
<div className="flex h-full flex-col">
|
<div className="flex h-full flex-col">
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,7 @@ export function AuthProvider({ children }): React.ReactElement {
|
||||||
const cookies = new Cookies();
|
const cookies = new Cookies();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const storedAccessToken = localStorage.getItem("access_token");
|
const storedAccessToken = cookies.get("access_token");
|
||||||
if (storedAccessToken) {
|
if (storedAccessToken) {
|
||||||
setAccessToken(storedAccessToken);
|
setAccessToken(storedAccessToken);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,9 @@ function ApiInterceptor() {
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const cookies = new Cookies();
|
const cookies = new Cookies();
|
||||||
|
|
||||||
|
console.log(accessToken);
|
||||||
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const interceptor = api.interceptors.response.use(
|
const interceptor = api.interceptors.response.use(
|
||||||
(response) => response,
|
(response) => response,
|
||||||
|
|
|
||||||
|
|
@ -18,12 +18,14 @@ import {
|
||||||
import {
|
import {
|
||||||
addUser,
|
addUser,
|
||||||
deleteUser,
|
deleteUser,
|
||||||
|
getLoggedUser,
|
||||||
getUsersPage,
|
getUsersPage,
|
||||||
updateUser,
|
updateUser,
|
||||||
} from "../../controllers/API";
|
} from "../../controllers/API";
|
||||||
import ConfirmationModal from "../../modals/ConfirmationModal";
|
import ConfirmationModal from "../../modals/ConfirmationModal";
|
||||||
import UserManagementModal from "../../modals/UserManagementModal";
|
import UserManagementModal from "../../modals/UserManagementModal";
|
||||||
import { alertContext } from "../../contexts/alertContext";
|
import { alertContext } from "../../contexts/alertContext";
|
||||||
|
import { AuthContext } from "../../contexts/authContext";
|
||||||
|
|
||||||
export default function AdminPage() {
|
export default function AdminPage() {
|
||||||
const [inputValue, setInputValue] = useState("");
|
const [inputValue, setInputValue] = useState("");
|
||||||
|
|
@ -33,6 +35,7 @@ export default function AdminPage() {
|
||||||
const [loadingUsers, setLoadingUsers] = useState(true);
|
const [loadingUsers, setLoadingUsers] = useState(true);
|
||||||
const [totalRowsCount, setTotalRowsCount] = useState(0);
|
const [totalRowsCount, setTotalRowsCount] = useState(0);
|
||||||
const { setErrorData, setSuccessData } = useContext(alertContext);
|
const { setErrorData, setSuccessData } = useContext(alertContext);
|
||||||
|
const { setUserData, getAuthentication, isAuthenticated } = useContext(AuthContext);
|
||||||
|
|
||||||
const userList = useRef([]);
|
const userList = useRef([]);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue