Task: Add auth context and provider and add routes and route wrapper and more configs and utils
This commit is contained in:
21
src/routes/AuthRoute.tsx
Normal file
21
src/routes/AuthRoute.tsx
Normal file
@@ -0,0 +1,21 @@
|
||||
import { useAuthContext } from '@/context/AuthContext'
|
||||
import AccessDenied from '@/pages/Error/403'
|
||||
import { Route } from 'react-router-dom'
|
||||
|
||||
const AuthRoute = (props: any) => {
|
||||
const { component, ...rest } = props
|
||||
const { isLogin } = useAuthContext()
|
||||
|
||||
if (!isLogin()) {
|
||||
return (<AccessDenied />)
|
||||
}
|
||||
|
||||
return (
|
||||
<Route
|
||||
{...rest}
|
||||
render={component}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
export default AuthRoute
|
||||
Reference in New Issue
Block a user