rolespicker-fix
This commit is contained in:
@@ -2,48 +2,45 @@ import { useAuth } from '../context/auth'
|
||||
import { DataProvider } from '../context/data'
|
||||
import { TableSortProvider } from '../context/sort'
|
||||
import AdminPage from '../routes/admin'
|
||||
import { Show, createEffect } from 'solid-js'
|
||||
|
||||
/**
|
||||
* Компонент защищенного маршрута
|
||||
*/
|
||||
export const ProtectedRoute = () => {
|
||||
console.log('[ProtectedRoute] Checking authentication...')
|
||||
const auth = useAuth()
|
||||
const isReady = auth.isReady()
|
||||
const authenticated = auth.isAuthenticated()
|
||||
|
||||
console.log(`[ProtectedRoute] Auth state: ready=${isReady}, authenticated=${authenticated}`)
|
||||
createEffect(() => {
|
||||
if (auth.isReady() && !auth.isAuthenticated()) {
|
||||
window.location.href = '/login'
|
||||
}
|
||||
})
|
||||
|
||||
// Если авторизация еще не готова, показываем загрузку
|
||||
if (!isReady) {
|
||||
console.log('[ProtectedRoute] Auth not ready, showing loading...')
|
||||
return (
|
||||
<div class="loading-screen">
|
||||
<div class="loading-spinner" />
|
||||
<div>Инициализация авторизации...</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
// Если авторизация готова, но пользователь не аутентифицирован
|
||||
if (!authenticated) {
|
||||
console.log('[ProtectedRoute] Not authenticated, redirecting to login...')
|
||||
// Используем window.location.href для редиректа
|
||||
window.location.href = '/login'
|
||||
return (
|
||||
<div class="loading-screen">
|
||||
<div class="loading-spinner" />
|
||||
<div>Перенаправление на страницу входа...</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
console.log('[ProtectedRoute] Auth ready and authenticated, rendering admin panel...')
|
||||
return (
|
||||
<DataProvider>
|
||||
<TableSortProvider>
|
||||
<AdminPage apiUrl={`${location.origin}/graphql`} />
|
||||
</TableSortProvider>
|
||||
</DataProvider>
|
||||
<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>
|
||||
)
|
||||
}
|
||||
|
Reference in New Issue
Block a user