Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
368 B
35
Indexable
Never
import React, { useContext } from 'react';
import { Route, Navigate } from 'react-router-dom';
import { AuthContext } from '../context/AuthContext';

function Protected({ children }) {
    const { user } = useContext(AuthContext);

    if (!user) {
        return <Navigate to="/login" replace />;
    }

    return children;
}

export default Protected;