forked from polka_billy/porridger
Added type definitions for components, functions, data Added guards for network responses fixes #8
20 lines
420 B
TypeScript
20 lines
420 B
TypeScript
import { PropsWithChildren, useEffect } from "react"
|
|
import { getToken } from "../utils/auth"
|
|
import { useNavigate } from "react-router-dom"
|
|
|
|
function WithToken({ children }: PropsWithChildren) {
|
|
const navigate = useNavigate()
|
|
|
|
useEffect(() => {
|
|
if (!getToken()) {
|
|
return navigate("/login")
|
|
}
|
|
}, [navigate])
|
|
|
|
return (
|
|
<>{children}</>
|
|
)
|
|
}
|
|
|
|
export default WithToken
|