14 lines
433 B
TypeScript
14 lines
433 B
TypeScript
import { getAccessToken } from '@/features/authorization/api/identityAPI';
|
|
import { type PropsWithChildren } from 'react';
|
|
import { Navigate } from 'react-router-dom';
|
|
|
|
export const ProtectedRoute = ({ children }: PropsWithChildren) => {
|
|
if (!getAccessToken()) {
|
|
// If no token, redirect to login page
|
|
return <Navigate to="/login" replace />;
|
|
}
|
|
|
|
// If token exists, render the children components
|
|
return children;
|
|
};
|