58 lines
1.5 KiB
TypeScript
58 lines
1.5 KiB
TypeScript
import { useEffect } from 'react';
|
|
import { useNavigate } from 'react-router-dom';
|
|
import { isUserAuthenticated } from '../api/api';
|
|
import './Home.css';
|
|
|
|
const Home: React.FC = () => {
|
|
const navigate = useNavigate();
|
|
|
|
// ✅ VÉRIFICATION INITIALE DE L'AUTHENTIFICATION
|
|
useEffect(() => {
|
|
const checkAuth = () => {
|
|
if (!isUserAuthenticated()) {
|
|
console.log('❌ [Home] Utilisateur non authentifié, redirection vers /login/client');
|
|
navigate('/login/client', { replace: true });
|
|
}
|
|
};
|
|
|
|
checkAuth();
|
|
}, [navigate]);
|
|
|
|
// ✅ VÉRIFICATION CONTINUE (toutes les 5 secondes)
|
|
useEffect(() => {
|
|
const authInterval = setInterval(() => {
|
|
if (!isUserAuthenticated()) {
|
|
console.log('❌ [Home] Session expirée, redirection vers /login/client');
|
|
navigate('/login/client', { replace: true });
|
|
}
|
|
}, 5000);
|
|
|
|
return () => clearInterval(authInterval);
|
|
}, [navigate]);
|
|
|
|
const handleVideoClick = () => {
|
|
// ✅ Vérifier l'auth avant la navigation
|
|
if (!isUserAuthenticated()) {
|
|
console.log('❌ [handleVideoClick] Non authentifié');
|
|
navigate('/login/client', { replace: true });
|
|
return;
|
|
}
|
|
|
|
navigate('/user/nos-produits');
|
|
};
|
|
|
|
return (
|
|
<div className="home-container-fullscreen" onClick={handleVideoClick}>
|
|
<video
|
|
src="/teaser.MP4"
|
|
className="home-video-fullscreen"
|
|
autoPlay
|
|
muted
|
|
loop
|
|
playsInline
|
|
/>
|
|
</div>
|
|
);
|
|
};
|
|
|
|
export default Home; |