mirror of
https://github.com/ets-cfuhrman-pfe/EvalueTonSavoir.git
synced 2025-08-11 21:23:54 -04:00
added frontend room authentication navigation
This commit is contained in:
parent
98e3887bcd
commit
c04558e139
2 changed files with 19 additions and 1 deletions
|
|
@ -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 */}
|
||||
<Route
|
||||
path="/student/join-room"
|
||||
element={isAuthenticated ? <JoinRoom /> : <Navigate to="/login" />}
|
||||
element={( !isRoomRequireAuthentication || isAuthenticated ) ? <JoinRoom /> : <Navigate to="/login" />}
|
||||
/>
|
||||
|
||||
{/* Pages authentification */}
|
||||
|
|
|
|||
|
|
@ -105,6 +105,17 @@ class ApiService {
|
|||
}
|
||||
}
|
||||
|
||||
// Route to know if rooms need authentication to join
|
||||
public async getRoomsRequireAuth(): Promise<any> {
|
||||
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");
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue