feat: AuthContext, protected routes, admin page, fix VideoPlayer URL

This commit is contained in:
2026-03-14 14:31:08 +01:00
parent 324efcaa3d
commit aa15dc0f54
8 changed files with 538 additions and 18 deletions

View File

@@ -0,0 +1,15 @@
import { Navigate, Outlet, useLocation } from 'react-router-dom';
import { useAuthContext } from '../context/AuthContext';
export default function RequireAuth() {
const { user, loading } = useAuthContext();
const location = useLocation();
if (loading) return null;
if (!user) {
return <Navigate to="/login" state={{ from: location }} replace />;
}
return <Outlet />;
}

View File

@@ -20,10 +20,11 @@ export default function VideoPlayer({ storageType, storageKey }: VideoPlayerProp
return <YouTubePlayer videoId={storageKey} />;
}
const apiBase = import.meta.env.VITE_API_URL || '/api';
const url =
storageType === 'external'
? storageKey
: `${import.meta.env.VITE_API_URL}/stream/${storageKey}`;
: `${apiBase}/stream/${storageKey}`;
return <NativePlayer url={url} />;
}

View File

@@ -1,6 +1,6 @@
import { Link } from 'react-router-dom';
import { apiFetch } from '../../lib/api';
import type { User } from '../../hooks/useAuth';
import type { User } from '../../context/AuthContext';
interface HeaderProps {
theme: 'dark' | 'light';
@@ -39,6 +39,11 @@ export default function Header({ theme, onToggleTheme, user, onLogout }: HeaderP
Playlists
</Link>
)}
{user && (
<Link to="/admin" className="font-mono text-xs text-od-muted hover:text-od-accent transition-colors">
admin
</Link>
)}
</nav>
{/* Right — thème + auth */}

View File

@@ -1,6 +1,6 @@
import { Outlet } from 'react-router-dom';
import Header from './Header';
import { useAuth } from '../../hooks/useAuth';
import { useAuthContext } from '../../context/AuthContext';
interface LayoutProps {
theme: 'dark' | 'light';
@@ -8,7 +8,7 @@ interface LayoutProps {
}
export default function Layout({ theme, onToggleTheme }: LayoutProps) {
const { user, loading, setUser } = useAuth();
const { user, loading, setUser } = useAuthContext();
return (
<div className="min-h-screen bg-od-bg text-od-text">