diff --git a/backend/controllers/UserControllers.js b/backend/controllers/UserControllers.js
index 5ee70308..14ca91ba 100644
--- a/backend/controllers/UserControllers.js
+++ b/backend/controllers/UserControllers.js
@@ -70,7 +70,7 @@ exports.userLogin = async (req, res) => {
secure: true,
});
- res.json({ accessToken: accessToken });
+ res.json({ accessToken: accessToken, superuser: user.superuser });
} catch (err) {
console.error(err);
res.status(500).json({ error: 'Erro durante o login.' });
diff --git a/frontend/src/contexts/auth.js b/frontend/src/contexts/auth.js
index b7cdeab9..5d1624c4 100644
--- a/frontend/src/contexts/auth.js
+++ b/frontend/src/contexts/auth.js
@@ -17,16 +17,22 @@ export const AuthProvider = ({ children }) => {
const signout = () => {
sessionStorage.removeItem("accessToken");
+ sessionStorage.removeItem("superuser");
};
const isAuthenticated = () => {
return signin()
}
+ const isSuperUser = () => {
+ const userType = sessionStorage.getItem("superuser");
+ return userType
+ }
+
return (
{children}
diff --git a/frontend/src/pages/Signin/index.js b/frontend/src/pages/Signin/index.js
index 2af56fa8..fc3379df 100644
--- a/frontend/src/pages/Signin/index.js
+++ b/frontend/src/pages/Signin/index.js
@@ -12,7 +12,7 @@ import { Text } from '@chakra-ui/react';
import axios from 'axios';
const Signin = () => {
- const { signin, isAuthenticated } = useAuth();
+ const { signin, isSuperUser } = useAuth();
const navigate = useNavigate();
const [email, setEmail] = useState("");
@@ -28,9 +28,12 @@ const Signin = () => {
if (response.data.accessToken) {
sessionStorage.setItem("accessToken", response.data.accessToken);
- sessionStorage.setItem("user", JSON.stringify({email, senha}));
+ sessionStorage.setItem("superuser", response.data.superuser);
+
signin();
-
+ console.log("oi")
+ console.log( sessionStorage.getItem("superuser"))
+ console.log(isSuperUser())
navigate("/home");
diff --git a/frontend/src/routes/index.js b/frontend/src/routes/index.js
index d2a3da97..418ef830 100644
--- a/frontend/src/routes/index.js
+++ b/frontend/src/routes/index.js
@@ -12,7 +12,7 @@ import Recommendations from "../pages/Recommendations";
import SendStudent from "../pages/SendStudents";
const RoutesApp = () => {
- const { isAuthenticated } = useAuth();
+ const { isAuthenticated, isSuperUser } = useAuth();
return (
@@ -20,53 +20,64 @@ const RoutesApp = () => {
} />
} />
} />
-
- {/* Utilize o componente Outlet para renderizar rotas aninhadas */}
- :
- }
- />
- :
- }
- />
- :
- }
- />
- :
- }
- />
- :
- }
- />
- :
- }
- />
- :
- }
- />
+
+ {!isSuperUser() ? (
+ <>
+ :
+ }
+ />
+ :
+ }
+ />
+ :
+ }
+ />
+ :
+ }
+ />
+ :
+ }
+ />
+ :
+ }
+ />
+ :
+ }
+ />
+ >
+ ) : (
+ :
+ }
+ />
+ )}
);
-};
+}
export default RoutesApp;
+