Auth provider added to the project

This commit is contained in:
مهرزاد قدرتی
2025-08-16 15:42:58 +03:30
parent 0548118208
commit 8a41aad9b9
10 changed files with 165 additions and 85 deletions

View File

@@ -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 />;
}