1- import React , { useEffect } from 'react' ;
2- import { Provider , useSelector } from 'react-redux' ;
1+ import React from 'react' ;
2+ import { Provider } from 'react-redux' ;
33import { Route , BrowserRouter as Router , Routes } from 'react-router' ;
44
5+ import Access from './components/Access.jsx' ;
56import Forgot from './pages/forgot/index.jsx' ;
67import Login from './pages/login/index.jsx' ;
78import ManageComments from './pages/manage-comments/index.jsx' ;
@@ -11,31 +12,6 @@ import Register from './pages/register/index.jsx';
1112import User from './pages/user/index.jsx' ;
1213import { store } from './store/index.js' ;
1314
14- const Access = ( props ) => {
15- const user = useSelector ( ( state ) => state . user ) ;
16-
17- useEffect ( ( ) => {
18- const meta = props . meta ?? { } ;
19- const basename = props . basename ?? '' ;
20- const emptyUser = ! user ?. objectId ;
21- const currentPath = location . pathname . replace ( basename , '' ) || '/' ;
22- const redirectPath = currentPath . startsWith ( '/' ) ? currentPath : `/${ currentPath } ` ;
23-
24- if ( emptyUser ) {
25- location . href = `${ basename } /ui/login?redirect=${ redirectPath } ` ;
26- return ;
27- }
28-
29- const noPermission = meta . auth ? meta . auth !== user . type : false ;
30-
31- if ( noPermission ) {
32- location . href = `${ basename } /ui/profile` ;
33- }
34- } , [ user , props . meta , props . basename ] ) ;
35-
36- return user ? props . children : null ;
37- } ;
38-
3915export default function App ( ) {
4016 const basePath = location . pathname . match ( / ( .* ?) \/ u i / u) ?. [ 1 ] ?? '/' ;
4117
0 commit comments