| import { useAuth } from "../hooks/useAuth"; |
| import { Navigate } from "react-router"; |
| import React from 'react' |
|
|
| const Protected = ({children}) => { |
| const { loading,user } = useAuth() |
|
|
|
|
| if(loading){ |
| return ( |
| <main style={{ |
| display: 'flex', |
| justifyContent: 'center', |
| alignItems: 'center', |
| height: '100vh', |
| backgroundColor: '#0d1117', |
| color: '#e6edf3', |
| fontFamily: "system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif" |
| }}> |
| <h2>Loading...</h2> |
| </main> |
| ) |
| } |
|
|
| if(!user){ |
| return <Navigate to={'/login'} /> |
| } |
| |
| return children |
| } |
|
|
| export default Protected |