Files
core/panel/ui/ProtectedRoute.tsx
Untone b7abb8d8a1
Some checks failed
Deploy on push / deploy (push) Failing after 5s
rolespicker-fix
2025-07-25 12:27:04 +03:00

47 lines
1.2 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { createEffect, Show } from 'solid-js'
import { useAuth } from '../context/auth'
import { DataProvider } from '../context/data'
import { TableSortProvider } from '../context/sort'
import AdminPage from '../routes/admin'
/**
* Компонент защищенного маршрута
*/
export const ProtectedRoute = () => {
const auth = useAuth()
createEffect(() => {
if (auth.isReady() && !auth.isAuthenticated()) {
window.location.href = '/login'
}
})
return (
<Show
when={auth.isReady()}
fallback={
<div class="loading-screen">
<div class="loading-spinner" />
<div>Инициализация авторизации...</div>
</div>
}
>
<Show
when={auth.isAuthenticated()}
fallback={
<div class="loading-screen">
<div class="loading-spinner" />
<div>Перенаправление на страницу входа...</div>
</div>
}
>
<DataProvider>
<TableSortProvider>
<AdminPage apiUrl={`${location.origin}/graphql`} />
</TableSortProvider>
</DataProvider>
</Show>
</Show>
)
}