chore: lint

This commit is contained in:
karishmas6
2024-09-25 15:43:24 +05:30
parent 8baa128852
commit 01dc8ade02

View File

@@ -4,33 +4,33 @@ import { useNavigate } from 'react-router-dom';
import { useGlobalInfoStore } from "../context/globalInfo"; import { useGlobalInfoStore } from "../context/globalInfo";
interface UserRouteProps { interface UserRouteProps {
children: ReactNode; children: ReactNode;
} }
const UserRoute: React.FC<UserRouteProps> = ({ children }) => { const UserRoute: React.FC<UserRouteProps> = ({ children }) => {
const [ok, setOk] = useState(true); const [ok, setOk] = useState(true);
const navigate = useNavigate(); const navigate = useNavigate();
const { notify } = useGlobalInfoStore(); const { notify } = useGlobalInfoStore();
useEffect(() => { useEffect(() => {
fetchUser(); fetchUser();
}, []); }, []);
const fetchUser = async () => { const fetchUser = async () => {
try { try {
const { data } = await axios.get('/api/current-user'); const { data } = await axios.get('/api/current-user');
if (data.ok) { if (data.ok) {
setOk(true); setOk(true);
} }
} catch (err: any) { } catch (err: any) {
setOk(false); setOk(false);
notify('error', err.message || 'Please login again to continue'); notify('error', err.message || 'Please login again to continue');
navigate('/'); navigate('/');
} }
}; };
// Display loading message while fetching user data // Display loading message while fetching user data
return <div>{!ok ? <p>Loading...</p> : <>{children}</>}</div>; return <div>{!ok ? <p>Loading...</p> : <>{children}</>}</div>;
}; };
export default UserRoute; export default UserRoute;