Initial commit
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
import { Navigate, useLocation } from 'react-router-dom'
|
||||
import type { ReactNode } from 'react'
|
||||
import { Spinner } from '../components/ui'
|
||||
import { STUDENT_ROUTES } from '../lib/routes'
|
||||
import { useStudentAuth } from './StudentAuthContext'
|
||||
|
||||
/**
|
||||
* Trasa kursanta. Niezalogowany trafia na logowanie Akademii.
|
||||
*
|
||||
* Zabezpieczenie interfejsu, nie zastepuje regul po stronie backendu.
|
||||
* Backend i tak odrzuci zadanie bez tokenu kursanta, a token panelu nie
|
||||
* otworzy /api/academy/**.
|
||||
*/
|
||||
export function RequireStudent({ children }: { children: ReactNode }) {
|
||||
const { student, loading } = useStudentAuth()
|
||||
const location = useLocation()
|
||||
|
||||
if (loading) {
|
||||
return (
|
||||
<div className="flex min-h-screen items-center justify-center">
|
||||
<Spinner label="Sprawdzanie sesji..." />
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
if (!student) {
|
||||
// sciezka razem z parametrami: odtwarzacz trzyma biezaca lekcje w ?lekcja=
|
||||
return <Navigate to={STUDENT_ROUTES.login} replace state={{ from: location.pathname + location.search }} />
|
||||
}
|
||||
|
||||
return <>{children}</>
|
||||
}
|
||||
Reference in New Issue
Block a user