diff --git a/client/src/App.tsx b/client/src/App.tsx
index 5199afa..3fad6fd 100644
--- a/client/src/App.tsx
+++ b/client/src/App.tsx
@@ -28,6 +28,7 @@ import OAuthCallback from './pages/AuthManager/callback/AuthCallback';
const App: React.FC = () => {
const [isAuthenticated, setIsAuthenticated] = useState(ApiService.isLoggedIn());
const [isTeacherAuthenticated, setIsTeacherAuthenticated] = useState(ApiService.isLoggedInTeacher());
+ const [isRoomRequireAuthentication, setRoomsRequireAuth] = useState(null);
const location = useLocation();
// Check login status every time the route changes
@@ -37,7 +38,13 @@ const App: React.FC = () => {
setIsTeacherAuthenticated(ApiService.isLoggedInTeacher());
};
+ const fetchAuthenticatedRooms = async () => {
+ const data = await ApiService.getRoomsRequireAuth();
+ setRoomsRequireAuth(data);
+ };
+
checkLoginStatus();
+ fetchAuthenticatedRooms();
}, [location]);
const handleLogout = () => {
@@ -76,7 +83,7 @@ const App: React.FC = () => {
{/* Pages espace étudiant */}
: }
+ element={( !isRoomRequireAuthentication || isAuthenticated ) ? : }
/>
{/* Pages authentification */}
diff --git a/client/src/services/ApiService.tsx b/client/src/services/ApiService.tsx
index d5c0b28..909f29b 100644
--- a/client/src/services/ApiService.tsx
+++ b/client/src/services/ApiService.tsx
@@ -105,6 +105,17 @@ class ApiService {
}
}
+ // Route to know if rooms need authentication to join
+ public async getRoomsRequireAuth(): Promise {
+ const url: string = this.constructRequestUrl(`/auth/getRoomsRequireAuth`);
+ const result: AxiosResponse = await axios.get(url);
+
+ if (result.status == 200) {
+ return result.data.roomsRequireAuth;
+ }
+ return false;
+ }
+
public logout(): void {
return localStorage.removeItem("jwt");
}