Skip to content

Instantly share code, notes, and snippets.

@paulweezydesign
Created October 6, 2024 11:57
Show Gist options
  • Save paulweezydesign/28fbc7d11431f19e80a1ab8dd46298f3 to your computer and use it in GitHub Desktop.
Save paulweezydesign/28fbc7d11431f19e80a1ab8dd46298f3 to your computer and use it in GitHub Desktop.
import React, { useContext } from 'react';
import { AuthContext } from './AuthProvider';
import { Navigate } from 'react-router-dom';
const ProtectedRoute = ({ children }) => {
const { user, loading } = useContext(AuthContext);
if (loading) {
return <div>Loading...</div>;
}
if (!user) {
return <Navigate to="/login" replace />;
}
return children;
};
export default ProtectedRoute;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment