feat(frontend): useAuth /auth/me, videos list + locked flag, VITE_API_URL
Some checks failed
CI/CD — Build & Deploy / Build (push) Failing after 40s
CI/CD — Build & Deploy / Deploy to VPS (push) Has been skipped

This commit is contained in:
2026-03-14 08:06:51 +01:00
parent 5afcad487e
commit 0591cd4528
4 changed files with 124 additions and 37 deletions

View File

@@ -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<User | null>(null);
const [loading, setLoading] = useState(true);
@@ -19,8 +25,8 @@ export function useAuth(): AuthState {
useEffect(() => {
let cancelled = false;
apiFetch<User>('/profile')
.then((u) => { if (!cancelled) setUser(u); })
apiFetch<MeResponse>('/auth/me')
.then((res) => { if (!cancelled) setUser(res.data.user); })
.catch(() => { if (!cancelled) setUser(null); })
.finally(() => { if (!cancelled) setLoading(false); });