From 0591cd45287fca89ab6c4f02f924252d20748af3 Mon Sep 17 00:00:00 2001 From: Tetardtek Date: Sat, 14 Mar 2026 08:06:51 +0100 Subject: [PATCH] feat(frontend): useAuth /auth/me, videos list + locked flag, VITE_API_URL --- frontend/src/hooks/useAuth.ts | 10 ++- frontend/src/lib/api.ts | 4 +- frontend/src/pages/HomePage.tsx | 144 +++++++++++++++++++++++++------- frontend/src/vite-env.d.ts | 3 +- 4 files changed, 124 insertions(+), 37 deletions(-) diff --git a/frontend/src/hooks/useAuth.ts b/frontend/src/hooks/useAuth.ts index d6214f1..33ffc0a 100644 --- a/frontend/src/hooks/useAuth.ts +++ b/frontend/src/hooks/useAuth.ts @@ -5,6 +5,7 @@ export interface User { id: number; email: string; nickname: string; + subscriptionLevel?: number; } interface AuthState { @@ -12,6 +13,11 @@ interface AuthState { loading: boolean; } +interface MeResponse { + success: boolean; + data: { user: User }; +} + export function useAuth(): AuthState { const [user, setUser] = useState(null); const [loading, setLoading] = useState(true); @@ -19,8 +25,8 @@ export function useAuth(): AuthState { useEffect(() => { let cancelled = false; - apiFetch('/profile') - .then((u) => { if (!cancelled) setUser(u); }) + apiFetch('/auth/me') + .then((res) => { if (!cancelled) setUser(res.data.user); }) .catch(() => { if (!cancelled) setUser(null); }) .finally(() => { if (!cancelled) setLoading(false); }); diff --git a/frontend/src/lib/api.ts b/frontend/src/lib/api.ts index 2319af1..017667b 100644 --- a/frontend/src/lib/api.ts +++ b/frontend/src/lib/api.ts @@ -1,4 +1,6 @@ -const BASE = '/api'; +// En dev : VITE_API_URL absent → proxy Vite sur /api → localhost:4000 +// En prod : VITE_API_URL=https://origins.tetardtek.com/api +const BASE = import.meta.env.VITE_API_URL || '/api'; export async function apiFetch(path: string, init?: RequestInit): Promise { const res = await fetch(`${BASE}${path}`, { diff --git a/frontend/src/pages/HomePage.tsx b/frontend/src/pages/HomePage.tsx index f575a70..d6a82f9 100644 --- a/frontend/src/pages/HomePage.tsx +++ b/frontend/src/pages/HomePage.tsx @@ -1,56 +1,136 @@ +import { useState, useEffect } from 'react'; +import { Link } from 'react-router-dom'; +import { apiFetch } from '../lib/api'; + +interface Video { + id: number; + title: string; + description: string; + requiredLevel: number; + locked: boolean; + thumbnailUrl?: string; +} + +interface VideosResponse { + success: boolean; + data: Video[]; +} + export default function HomePage() { + const [videos, setVideos] = useState([]); + const [loading, setLoading] = useState(true); + + useEffect(() => { + apiFetch('/videos') + .then((res) => setVideos(res.data)) + .catch(() => setVideos([])) + .finally(() => setLoading(false)); + }, []); + + const free = videos.filter((v) => !v.locked); + const premium = videos.filter((v) => v.locked); + return (
{/* Hero */}
-

- Vidéos & formations -

+

Vidéos & formations

Contenu libre et premium — connecte-toi pour accéder aux formations complètes.

- {/* Accès libre */} -
-

- Accès libre -

+ {loading && (
- - + {[...Array(4)].map((_, i) => )}
-
+ )} - {/* Premium */} -
-

- Premium -

-
- - -
-
+ {!loading && ( + <> + {free.length > 0 && ( +
+

+ Accès libre +

+
+ {free.map((v) => )} +
+
+ )} + + {premium.length > 0 && ( +
+

+ Premium +

+
+ {premium.map((v) => )} +
+
+ )} + + {videos.length === 0 && ( +

Aucune vidéo disponible pour l'instant.

+ )} + + )}
); } -function VideoCardPlaceholder({ tier }: { tier: 'free' | 'premium' }) { +function VideoCard({ video }: { video: Video }) { + const inner = ( +
+ {/* Thumbnail */} +
+ {video.thumbnailUrl && ( + {video.title} + )} + {video.locked && ( +
+ +
+ )} +
+ +

{video.title}

+ + {video.description && ( +

{video.description}

+ )} + +
+ {video.locked ? ( + + Premium + + ) : ( + + Libre + + )} +
+
+ ); + + if (video.locked) return
{inner}
; + + return {inner}; +} + +function VideoCardSkeleton() { return (
- {/* Thumbnail */} -
- {/* Title skeleton */} -
-
- {tier === 'premium' && ( - - Premium - - )} +
+
+
); } diff --git a/frontend/src/vite-env.d.ts b/frontend/src/vite-env.d.ts index 5f487a1..61f1354 100644 --- a/frontend/src/vite-env.d.ts +++ b/frontend/src/vite-env.d.ts @@ -1,9 +1,8 @@ /// interface ImportMetaEnv { - // URL de base SuperOAuth — ex: https://superoauth.tetardtek.com - // Flow login : VITE_SUPEROAUTH_URL + /api/v1/auth/oauth/:provider?redirectUrl= readonly VITE_SUPEROAUTH_URL: string; + readonly VITE_API_URL: string; } interface ImportMeta {