Auth provider added to the project
This commit is contained in:
@@ -1,9 +1,11 @@
|
||||
import { getAccessToken } from '@/features/authorization/api/identityAPI';
|
||||
import { useAuth } from '@/hooks/useAuth';
|
||||
import { type PropsWithChildren } from 'react';
|
||||
import { Navigate } from 'react-router-dom';
|
||||
|
||||
export const ProtectedRoute = ({ children }: PropsWithChildren) => {
|
||||
if (!getAccessToken()) {
|
||||
const auth = useAuth();
|
||||
|
||||
if (!auth.accessToken) {
|
||||
// If no token, redirect to login page
|
||||
return <Navigate to="/login" replace />;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user