added advertising
This commit is contained in:
13
src/App.js
13
src/App.js
@@ -1,6 +1,6 @@
|
||||
// src/App.jsx
|
||||
import { useEffect, useRef } from 'react';
|
||||
import { BrowserRouter, Routes, Route, useLocation } from 'react-router-dom';
|
||||
import { BrowserRouter, Routes, Route, useLocation, Navigate } from 'react-router-dom';
|
||||
import { AuthProvider } from './context/AuthContext';
|
||||
import { ThemeProvider } from './context/ThemeContext';
|
||||
import { useAuthContext } from './context/AuthContext';
|
||||
@@ -11,6 +11,7 @@ import MainFeed from './pages/MainFeed';
|
||||
import ChatPage from './pages/ChatPage';
|
||||
import ChatListPage from './pages/ChatListPage';
|
||||
import ReviewsPage from './pages/ReviewsPage';
|
||||
import AdminAdsPage from './pages/AdminAdsPage';
|
||||
import './styles/chat.css';
|
||||
|
||||
function ScrollToTop() {
|
||||
@@ -38,6 +39,15 @@ function UnreadListener() {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Защита десктоп-only админ-роутов: доступен только при isAdmin.
|
||||
// Дополнительная проверка на уровне роута — defense in depth к тому,
|
||||
// что пункт меню в Sidebar скрыт для не-админов.
|
||||
function AdminRoute({ children }) {
|
||||
const { isAdmin } = useAuthContext();
|
||||
if (!isAdmin) return <Navigate to="/feed" replace />;
|
||||
return children;
|
||||
}
|
||||
|
||||
function App() {
|
||||
return (
|
||||
<ThemeProvider>
|
||||
@@ -51,6 +61,7 @@ function App() {
|
||||
<Route path="/reviews" element={<ReviewsPage />} />
|
||||
<Route path="/chats" element={<ChatListPage />} />
|
||||
<Route path="/chats/:chatId" element={<ChatPage />} />
|
||||
<Route path="/admin/ads" element={<AdminRoute><AdminAdsPage /></AdminRoute>} />
|
||||
<Route path="*" element={<LandingPage />} />
|
||||
</Routes>
|
||||
</BrowserRouter>
|
||||
|
||||
Reference in New Issue
Block a user