Add useEffect hook to handle authority navigation and log response in YourProjectsPage
This commit is contained in:
parent
f6b2d17b97
commit
164ff781b3
2 changed files with 12 additions and 8 deletions
|
@ -1,4 +1,4 @@
|
|||
import { useState } from "react";
|
||||
import { useState, useEffect } from "react";
|
||||
|
||||
import LoginPage from "./LoginPage";
|
||||
import { useNavigate } from "react-router-dom";
|
||||
|
@ -6,6 +6,8 @@ import { useNavigate } from "react-router-dom";
|
|||
function App(): JSX.Element {
|
||||
const navigate = useNavigate();
|
||||
const [authority, setAuthority] = useState(0);
|
||||
|
||||
useEffect(() => {
|
||||
if (authority === 1) {
|
||||
navigate("/admin");
|
||||
} else if (authority === 2) {
|
||||
|
@ -13,6 +15,7 @@ function App(): JSX.Element {
|
|||
} else if (authority === 3) {
|
||||
navigate("/user");
|
||||
}
|
||||
}, [authority, navigate]);
|
||||
|
||||
return <LoginPage setAuthority={setAuthority} />;
|
||||
}
|
||||
|
|
|
@ -11,6 +11,7 @@ function UserProjectPage(): JSX.Element {
|
|||
const username = localStorage.getItem("username") ?? ""; // replace with actual username
|
||||
const token = localStorage.getItem("accessToken") ?? ""; // replace with actual token
|
||||
const response = await api.getUserProjects(username, token);
|
||||
console.log(response);
|
||||
if (response.success) {
|
||||
setProjects(response.data ?? []);
|
||||
} else {
|
||||
|
|
Loading…
Reference in a new issue