Hackathon finished
This commit is contained in:
19
front/src/components/WithToken.jsx
Normal file
19
front/src/components/WithToken.jsx
Normal file
@ -0,0 +1,19 @@
|
||||
import { useEffect } from "react"
|
||||
import { getToken } from "../utils/auth"
|
||||
import { useNavigate } from "react-router-dom"
|
||||
|
||||
function WithToken({ children }) {
|
||||
const navigate = useNavigate()
|
||||
|
||||
useEffect(() => {
|
||||
if (!getToken()) {
|
||||
return navigate("/login")
|
||||
}
|
||||
}, [])
|
||||
|
||||
return (
|
||||
<>{children}</>
|
||||
)
|
||||
}
|
||||
|
||||
export default WithToken
|
Reference in New Issue
Block a user