import { useEffect, useMemo, useState } from 'react' import { FurumiPlayer } from './FurumiPlayer' import './App.css' type UserProfile = { sub: string name?: string email?: string } const NO_AUTH_STORAGE_KEY = 'furumiNodePlayer.runWithoutAuth' function App() { const [loading, setLoading] = useState(true) const [user, setUser] = useState(null) const [error, setError] = useState(null) const [runWithoutAuth, setRunWithoutAuth] = useState(() => { try { return window.localStorage.getItem(NO_AUTH_STORAGE_KEY) === '1' } catch { return false } }) const apiBase = useMemo(() => import.meta.env.VITE_API_BASE_URL ?? '', []) useEffect(() => { if (runWithoutAuth) { setError(null) setUser({ sub: 'noauth', name: 'No Auth' }) setLoading(false) return } const loadMe = async () => { try { const response = await fetch(`${apiBase}/api/me`, { credentials: 'include', }) if (response.status === 401) { setUser(null) return } if (!response.ok) { throw new Error(`Request failed with status ${response.status}`) } const data = await response.json() setUser(data.user ?? null) } catch (err) { setError(err instanceof Error ? err.message : 'Failed to load session') } finally { setLoading(false) } } void loadMe() }, [apiBase, runWithoutAuth]) const loginUrl = `${apiBase}/api/login` const logoutUrl = `${apiBase}/api/logout` const playerApiRoot = `${apiBase}/api` return ( <> {!loading && (user || runWithoutAuth) ? ( ) : (

OIDC Login

Авторизация обрабатывается на Express сервере.

{loading &&

Проверяю сессию...

} {error &&

Ошибка: {error}

} {!loading && runWithoutAuth && (

Режим без авторизации включён. Для входа отключи настройку выше.

)} {!loading && !user && ( Войти через OIDC )} {!loading && user && (

ID: {user.sub}

{user.name && (

Имя: {user.name}

)} {user.email && (

Email: {user.email}

)} {!runWithoutAuth && ( Выйти )}
)}
)} ) } export default App